Closed jingledongding closed 5 months ago
Does this API support the content type "application/octet-stream"?
Hey there! There is a certain format you have to use when uploading blobs via the API which we have documented here. Here is an example:
const JWT = 'YOUR_PINATA_JWT';
async function pinFileToIPFS() {
try {
const text = "Hello World!";
const blob = new Blob([text], { type: "text/plain" });
const data = new FormData();
data.append("file", blob);
const res = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS",
method: "POST",
headers: {
Authorization: `Bearer ${JWT}`,
},
body: data,
);
const resData = await res.json();
console.log(resData);
} catch (error) {
console.log(error);
}
};
We are currently rewriting the SDK to better handles cases like this!
It my code:`import {PINATA_JWT} from '@env'; import {useCallback} from 'react'; import ReactNativeBlobUtil from 'react-native-blob-util';
export function useStorageUpload() { const upload = useCallback( async (filePath: string): Promise<string | undefined> => { try { const file = await ReactNativeBlobUtil.fs.readFile(filePath, 'base64');
); return {upload}; }
request body:
--e2ebff34-8822-4e3d-820e-ba28a493e274 content-disposition: form-data; name="file" Content-Length: 96916 ... ... ... MJvXcA/JhsoRfYWPRLOoslkYl/6Btgea7lglcF2BRysw== --e2ebff34-8822-4e3d-820e-ba28a493e274--Response body:
{"error":"Invalid request format."}`platform:`System: OS: macOS 13.3.1 CPU: (10) arm64 Apple M1 Pro Memory: 72.78 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.8.0 path: ~/.nvm/versions/node/v20.8.0/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.9.0 path: ~/gm/GoodMorning/node_modules/.bin/npm Watchman: version: 2023.12.04.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.14.3 path: /Users/jingxiaopeng/.rbenv/shims/pod SDKs: iOS SDK: Platforms: