You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I've noticed a peculiar issue with Drive, wherein uploading anything other than a PDF puts a 0 byte file in S3.
The upload works fine the first time the service is started and then every subsequent upload other than a PDF uploads a 0 byte file.
My FileService for reference:
import{MultipartFileContract}from'@ioc:Adonis/Core/BodyParser';importFileValidatorfrom'./FormioValidator';importDrivefrom'@ioc:Adonis/Core/Drive';importretryfrom'async-await-retry';importLoggerfrom'@ioc:Adonis/Core/Logger';classFileService{/** * Function to upload file to storage. * The function returns an object that mimicks the fields mentioned in [form.io documentation](https://help.form.io/developers/file-storage#custom-url) * * @param {object} inputs Inputs object containing id and type of entity * @param {MultipartFileContract} file The file to be uploaded * * @return {object} Object containing data about the file uploaded. */publicasyncupload(inputs: {id?: string;type?: string;dir?: string},file: MultipartFileContract){awaitFileValidator.fire({ ...inputs, file },'upload');const{ id, type, dir }=inputs;letfilePath='';filePath+=type ? `${type}/` : '';filePath+=id ? id : '';if(dir){filePath=`${dir}`;}/** * Try uploading a file in S3, retry in case of exceptions * retriesMax: 10 (retry 10 times maximum) * interval: 100 (100ms interval) * interval grows exponentially with growth factor of 2 * Refer to [docs](https://www.npmjs.com/package/async-await-retry) for customization */file=awaitretry(async(file: MultipartFileContract,filePath: string)=>{// Upload file to driveawaitfile.moveToDisk(filePath);returnfile;},[file,filePath],{retriesMax: 10,interval: 100,onAttemptFail: (errorMsg: any)=>{Logger.debug(`Unsuccessful upload attempt #${errorMsg.currentRetry+1} for file ${file.clientName}`);},});return{fileName: file.fileName,name: file.clientName,mimetype: `${file.type}/${file.subtype}`,path: file.filePath,size: file.size,entity_type: inputs.type??null,entity_id: inputs.id??null,url: `/${encodeURIComponent(`${filePath!=='' ? `${filePath}/` : ''}${file.fileName}`)}`,};}}exportdefaultnewFileService();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
So I've noticed a peculiar issue with Drive, wherein uploading anything other than a PDF puts a 0 byte file in S3.
The upload works fine the first time the service is started and then every subsequent upload other than a PDF uploads a 0 byte file.
My FileService for reference:
Beta Was this translation helpful? Give feedback.
All reactions