my objective is to push an image data to media collection via rest api, using json, but I get an error message "No files were uploaded", and I'm using mongodb-community version
I'm using Postman to upload an image and post the data but it returns an error with "No files were uploaded
you are not uploading it
problem is in the upload part
Yes, you're right, the endpoint was incorrect. However, even though doing it right it still doesn't work for me. The endpoint is right, the content type is multipart/form-data, and the image is selected as a file. I don't know why there is http error 404
I'm still having the same issue. Tried with Postman and Insomnia, and the 404 error persists. Unable to figure it out. Even, I have installed payload on two different machines but the result is the same.
Instead of filename, change the key to file.
From the docs:
Send it all the data that your Collection requires, as well as a file
key containing the file that you'd like to upload.
that is exactly what I did. In both screenshots, the file is selected, but it still fails to upload to the media collection. It fails no matter what I do.
The first screenshot you have it very close, but there is an extra "n" on the end. It should just be
file
, not
filen
.
I was thinking maybe he doesn't allow create on permission section
Thank you for reply, but file or filename, these are name of the input, but the selection is file type, so, I think that shouldn't be a problem. This a plain code for media upload, and the user is admin, not editor.
can you share your media collection snippet here?
import { CollectionConfig } from "payload/types";;
const Media: CollectionConfig = {
slug: 'media',
admin: {
useAsTitle: 'title',
defaultColumns: ['filename', 'id'],
},
upload: true,
fields: [
{
name: 'alt',
type: 'text',
}
]
}
export default Media;
this is the same code as in the screenshot.
auth: false,
access: {
read: () => true,
create: () => true
},
add this above fields @artmelkon
just wanted to see if it works without any credentials
still getting 404
remove the
/create
. So just
http://localhost:4000/api/media
🙂
The "POST" automatically means "create"
I've created another test posing a new page. When I use /api/pages/create endpoint it fails, but when I use /api/pages it succeded, it is puzzling but it did work
Yes, it did work. Thanks
check it out this section, it showcases all operations you can do on a collection with the rest API - together with an example and the URL / rest operation you have to use
Glad it works now!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.