Hi,
I'm writing a custom media (audio) upload function. Since my storage is on S3, and I want to have custom API response, I opted to use a custom express route with LocalAPI instead of payload REST endpoint.
Since I manually upload the Media to S3, I want to use LocalAPI only to add a record to DB. However I ran to the following error when calling payload.create
method: MissingFile: No files were uploaded.
I do have disableLocalStorage
in my Audio
collection, it looks like this::
In my custom express route, I call Payload local API to create a Audio
record like this:
The error stack would lead me to this line: https://github.com/payloadcms/payload/blob/master/src/collections/operations/create.ts#L97
.
Is there anyway to ignore uploading file in my case ?
Thanks in advance for your helps !
Hey @henrituan — I can give you a few answers here. First up, a few questions:
I'm writing a custom media (audio) upload function. Since my storage is on S3, and I want to have custom API response, I opted to use a custom express route with LocalAPI instead of payload REST endpoint.
First up, what types of things are you trying to do to your custom response? You may be able to accomplish what you need with afterRead
hooks on a collection but if there's something else that you'd like to modify from our built-in REST responses, which you can't do now, I'd be happy to brainstorm how to expose what you need so you can re-use built-in endpoints. But, if you do indeed want to have a custom REST endpoint, this should be 100% doable.
Next, have you seen the payload-plugin-cloud-storage
package? It helps you automatically ship off files to S3 or similar, and this might be of use to you:
https://www.npmjs.com/package/payload-plugin-cloud-storage
Finally, if you do want to use Payload's Local API to upload files, right now the local create
operation requires a file path to a locally stored file, and then automatically parses all information it needs from the file that is read from disk. This however could be expanded on, so that the create
operation can directly take a file instead of reading it from disk. We would add a new property to the arguments called file
and then use that instead of getting a file by path.
This would all need to be done in the following file:
https://github.com/payloadcms/payload/blob/master/src/collections/operations/local/create.ts
If you would like to make a PR to the create operation, please do! Otherwise I think we can get to this shortly as well.
Let me know!
Thanks @jmikrut ,
1st question: My usecase is batch-uploading mp3 files. I used this library and it requires a custom REST response for each uploaded file in the batch.
I certainly can use other library like react-dropzone
to avoid this constraint, but I feel like an option to send file into payload.create
will be useful for many other usecases.
2nd question: yes, I did use payload-plugin-cloud-storage
, however there is some constraints in the plugin (I can't have file prefix in bucket name), so I stop using the library. I then implemented a simple S3 uploading function so the plugin is not so neccessary.
Finally: Yes I'll look into it and summit PR !
Star
Discord
online
Get dedicated engineering support directly from the Payload team.