Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How can I upload images or files to strapi using graphQl

Post

How can I upload images or files to strapi using graphQl

+2
−0

How can I upload images or files to strapi using graphQl.

I'm using Cloudinary as the image provider. The strapi admin panel works fine, uploads the images to cloudinary. But, when using graphQl mutation I get an error.

This is the mutation I've tried

''' mutation { createProject(data: { title: "$name", description: "$description", completed: $completed, start_date: "$startDate", end_date: "$endDate", project_logo: upload(file: $projectLogo){ name }, publishedAt: "${publishedAt}Z" }){ data{ id, attributes{ title, description, completed, start_date, end_date } } } }''';

I'm using flutter to pick the image and the graphql plugin to send the mutation. The image projectLogo is of Uint8List?

when I Try-Catch the error, this is what is showing

EXCEPTION=> Error on line 8, column 29: Expected an object field name ╷ 8 │ project_logo: upload(file: [137, 80.....])

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Relevant code for the request (3 comments)
Relevant code for the request
Alexei‭ wrote over 1 year ago

I am unfamiliar with Flutter, but I guess there must be some code to push the mutation (it seems like a JSON payload to me, is it a GraphQL query?). Not sure if that's relevant to the question, but it might be.

Phtremor‭ wrote over 1 year ago

Yes its a graphQl mutation. The Flutter code that's pushing the query works fine. For instance when I remove the project_logo field and value, I'm able to push and update the data to my strapi backend.

The problem I'm facing really is on how I can upload an image to strapi using a graphQl query.

Here's how strapi works with the images: it upload the file to media provider like cloudinary or google storage; it gets the ID from the provider and updates it's records in the DB.

There's something wrong with how I'm writing my query to update the image itself😬

TreciaKS‭ wrote over 1 year ago

I am not familiar with Flutter but I am confident that this article will help you but this one uses Nuxt.js v3 Article: https://strapi.io/blog/how-to-build-a-photo-sharing-app-with-nuxt-3-graph-ql-cloudinary-postgres-and-strapi