5

I want to upload file using REST Api. As per my reserch there are two ways for this.

  1. by passing base64 encoded string into form-data
  2. by passing file upload parameter into form-data

But I am confused which is best way for this.

I also want to accept multiple files types like jpg,jpeg,gif,png,txt,pdf,docx.

Does anyone have idea about this ? It will be really helpfull if anyone know how to implement this in a particular way.

1 Answer 1

1

Both methods you mentioned are valid for uploading files via REST API, but they have different use cases.

1. Base64-encoded string:

This method is useful when you need to include the file content as part of a larger JSON payload, for example when creating a new entity that includes a file attachment. By encoding the file content as a base64 string, you can include it as a field in the JSON payload and avoid the need to send a separate binary file.

2. File upload parameter:

This method is useful when you want to upload a file as a standalone operation, or when you need to upload a large file that may exceed the maximum JSON payload size. By sending the file as a separate binary parameter in the form-data, you can stream the file data directly to the server and avoid the need to buffer the entire file in memory.

For your use case of accepting file types like jpg, jpeg, gif, png, txt, pdf, and docx, you can use either method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.