How to upload a file through Carrierwave via the JSON API?

I am creating an API for processing files in Rails, and I need to have access to it through a separate stone. The API uses Carrierwave, and this part works without problems. What I do not understand how to do is to take an arbitrary file and deliver it to the API from the gem interface.

Carrierwave accepts its files as the results of File.open('foo.jpg') or as POST from the file field. I'm really not sure what I am doing to serialize the file and send it.

How to take the contents of a file and turn it into something that I can transfer and send via JSON?

+7
source share
1 answer

When an HTML form submits a file, what is actually happening is a special part of HTTP called a multipart request. In fact, the file is attached to the request.

The question will be answered which library you use for POST JSON for your api. Attaching a file to a request should be fairly common, but not all libraries can support it.

This article seems to give some good directions on how to do this.

+4
source

All Articles