Closed coderup2021 closed 1 year ago
when use web3.storage client to upload file, can success uploaded, but when I get filelist, the filename is changed(as you see in the picture)
here is my main code
export const uploadToWeb3 = ( filePath: string, apiToken: string, fileInfo: FileInfo ) => { return new Promise(async (resolve, reject) => { // Construct with token and endpoint const { uuid, name, size } = fileInfo; const key = `uploadingList.${uuid}`; const client = new Web3Storage({ token: apiToken }); const files = []; for await (const f of filesFromPath(filePath)) { files.push(f); } // Pack files into a CAR and send to web3.storage store.set(key, { uuid, name, size, status: UploadStatus.UPLOADING, progress: 0, }); try { const onStoredChunk = (bytes: number) => { const percentAdd = Number((bytes / size).toFixed(2)); const uploadingList = store.get('uploadingList') as {}; const originPercent = ((uploadingList as any)[uuid] as UploadingItem) .progress; const newPercent = originPercent + percentAdd; store.set(key, { uuid, name, size, status: newPercent >= 1 ? UploadStatus.COMPLETE : UploadStatus.UPLOADING, progress: newPercent >= 1 ? 1 : newPercent, }); }; const rootCid = await client.put( files as Iterable<Filelike>, { onStoredChunk, } as PutOptions ); // Promise<CIDString> setTimeout(() => { store.delete(key); }, 5000); resolve({}); } catch (error) { let message = ''; if (error instanceof Error) message = error.message; else message = String(error); store.set(`${key}.failReason`, message); store.set(`${key}.status`, UploadStatus.FAIL); reject({ error }); } }); };
please help!!!
I use this in my electron app(plan to development a desktop client to upload and manage web3.storage files) https://github.com/coderup2021/web3.storage-desktop
@coderup2021 that's a name for the upload as a whole - which may be 1 or more files. You can specify your own name using the name option https://web3.storage/docs/reference/js-client-library/#parameters
name
when use web3.storage client to upload file, can success uploaded, but when I get filelist, the filename is changed(as you see in the picture)
here is my main code
please help!!!
I use this in my electron app(plan to development a desktop client to upload and manage web3.storage files) https://github.com/coderup2021/web3.storage-desktop