Zubair Nabi
Zubair Nabi

Reputation: 1046

How can i use requestBody to upload an image as binary in phoenix/Elixir

So far i have been using

    swagger_path :create_tag do
    post "/tag"
    produces "application/json"
    description "register Tags"
    consumes "multipart/form-data"        
    parameters do 
    image :formData, :file,  "The file to upload.", required: true
    end
    response 200, "Success"
end

However i would like to use requestBody to get the binary data of the image, with above i am getting the image path, and have to work on Plug.Upload in controller.

would like to know the syntax using the requestBody of swagger in phoenix

Upvotes: 2

Views: 596

Answers (1)

Mike Buhot
Mike Buhot

Reputation: 4885

Binary file uploads are not supported in the swagger 2.0 spec used in phoenix_swagger:

Uploads where the payload is just the raw file contents are not supported in Swagger 2.0, because they are not multipart/form-data. That is, Swagger 2.0 does not support something like:

curl --upload-file archive.zip http://example.com/upload

The open_api_spex package targets swagger 3.0, which supports binary requestBody operations.

Upvotes: 1

Related Questions