I'm trying to upload files to Appwrite's storage bucket using the REST API, but I keep encountering the following error:
TypeScript
{
"message": "Param \"fileId\" is not optional.",
"code": 400,
"type": "general_argument_invalid",
"version": "1.6.1"
}
What I’ve Tried:
- I'm using a fileId generated by UUID.randomUUID() in Java, but I still get the error. Here's an example of the fileId I'm sending: 123e4567-e89b-12d3-a456-426614174000.
- I’ve also tried passing ID.unique() in the payload for fileId, but it doesn’t seem to work.
Here's my code;
TypeScript
public Map<String, Object> uploadFile(MultipartFile file) throws Exception {
String url = appwriteEndpoint + "/v1/storage/buckets/" + appwriteBucketId + "/files";
String fileId = UUID.randomUUID().toString().replace("-", "").substring(0, 36);
Map<String, Object> operations = new HashMap<>();
operations.put("query", "mutation CreateFile($bucketId: String!, $fileId: String!, $file: InputFile!) { storageCreateFile(bucketId: $bucketId, fileId: $fileId, file: $file) { id } }");
Map<String, Object> variables = new HashMap<>();
variables.put("bucketId", appwriteBucketId);
variables.put("fileId", fileId);
variables.put("file", null);
operations.put("variables", variables);
// Build multipart request here (details omitted for brevity)...
}
Questions:
- Are there additional constraints for the fileId parameter that I might be missing?
- Is there something wrong with the way I’m structuring the multipart/form-data payload?
- How should ID.unique() be handled if passed programmatically via REST?
TL;DR
Issue: Developers facing an error message stating "Param 'fileId' is not optional" when trying to upload files to Appwrite's storage bucket via the REST API.
Solution:
1. Ensure the fileId for the file is properly generated, try using UUID.randomUUID().toString() without modification.
2. Check if the multipart/form-data payload structure aligns with Appwrite's requirements.
3. Handle ID.unique() appropriately when passing it programmatically via REST to avoid errors.Recommended threads
- Frequent 500 Internal Server Errors - Pr...
PROJECT ID: 6951f2xxxxx1ee9e750a REGION: Singapore (sgp.cloud.appwrite.io) PLAN: Pro Our production application experiences **500 Internal Server Errors** mult...
- Issue with Custom SMTP
Hey everyone, I'm facing an issue when updating my Custom SMTP settings on Appwrite Cloud. The UI fails silently (no visual errors), but when checking the cons...
- Function running for more than 2 hours i...
This is my projectID: 669fe01b003800dd0503 Cloud functionID is 696ea05400147eb8eb3b I hope this doesn't count against my GB-hours?