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.

Cladiuss
1,3111 gold badge15 silver badges29 bronze badges
asked Feb 15, 2023 at 7:31

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.

answered Feb 16, 2023 at 10:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.