Elixir: File upload to a REST API with json data - api

I'm trying to upload a file to a rest api using HTTPoison.
I can get a file upload to work with the following code, but I need to replace {"name", "value"} with a json payload or find a way to have json/nested data be sent with same request.
url = 'https://sandbox.e-signlive.com/api/packages/dc337476-9841-454a-b5d4-fe5a2b60136d/documents'
headers = [{"Authorization", "secret_key"}]
HTTPoison.post!("httpbin.org/post", {:multipart, [{"name", "value"}, {:file, "/Path/to/document.pdf"}]}, headers)

It seems enctype is missing:
enctype="multipart/form-data"

Related

Read csv from s3 and upload to external api as multipart

I want to read the csv file from the s3 bucket using boto3 and upload it to external API using multipart/form-data request.
so far I am able to read the csv
response = s3.get_object(Bucket=bucket, Key=key)
body = response['Body']
Not sure on how to convert this body into multipart.
External api will be taking request in multipart/form-data.
Any Suggestions would be helpful.
Following method solved my issue.
body = response['Body'].read()
multipart_data = MultipartEncoder(
fields={
'file': (file_name, body, 'application/vnd.ms-excel'),
'field01': 'test'
}
)
.read() method will convert the file into binary string.

ArrayIndexOutOfBoundsException use karate 0.8.0 [duplicate]

I'm trying to upload images on specific slack channel using Karate but no luck, I tried multiple times with different steps but still have 200 response and the image is not displayed in the channel.
Tried to post text content and successfully found the text on the channel.
Bellow are 2 of my tries following the Karate documentation:
#post
Feature: Post images
Background:
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}
Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200
OR
Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200
Am I missing something? Tried the same examples found in Karate demo GitHub repository of uploading pdf and jpg but no luck.
Note: worked using Slack API UI.
You seem to be mixing up things, there is no need for a request body when you are using multipart. Your headers / params look off. Also based on the doc here, the name of the file-upload field is file. Try this:
Scenario: upload image
Given url 'https://slack.com/api/files.upload'
And multipart file file = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
When method post
Then status 200
If this doesn't work, take the help of someone who can understand how to interpret the Slack API doc. Or get a Postman test working, then you'll easily figure out what you missed.

Unable to upload multipart file in karate, Required request part '' not present

ActualAPIRequest OutputFromKarate
Trying to upload a json file for an api using karate. Since api takes multipart input i am passing multipart configurations in karate.
But Required request part 'inputData' not present error is coming. Is there any solution for this please?
I have attached actual input and result from karate screenshot for reference
Just make sure that the data type of inputData and maybe swaggerFile is JSON. Looks like you are sending a string.
Please refer to this section of the doc: https://github.com/intuit/karate#type-conversion
If the server does not like the charset being sent for each multipart, try * configure charset = null

Vb.Net Gmail API Send Message with attachment > 5Mb

On Gmail Api documentation i read that i've to make an HTTP request at "/upload/gmail/v1/users/userId/messages/send" when sending message larger then 5mb but i don't find any example how to implement this using the Client Library in .net
All the examples on the site refer to the "messages.Send" function that takes as parameter a raw message and the user id but i saw that there's another overload that also take the stream of the content to upload and the content type of it.
The problem is that i've no clue how to correctly call it.
Does anyone have successfully achived it ?
Thx for your answer
Simone
Simone, it's means that you use simple upload:
uploadType=media. For quick transfer of smaller files, for example, 5 MB or less.
You must use Multipart upload or Resumable upload (https://developers.google.com/gmail/api/guides/uploads)
You can send a post query with payload (see CURLOPT_POSTFIELDS, if use a CURL) on the https://www.googleapis.com/gmail/v1/users/me/messages/send?access_token=your_access_token&uploadType=multipart. Payload must contain json encoded message. Structure of this message for example:
$message = [
'message' => [
'raw' => str_replace(['+', '/'], ['-', '_'], base64_encode($mimeString)),
'threadId' => $yourThreadId
]
];
Variable $mimeString must contain correct mime string

How to render json without having .json at the end of the url

I want to implement ODATA formatting to my CakePHP REST API. My problem is CakePhp expects .json at the end of the resource to understand the response format.
How can I render json and remove ".json" part from my request url?
I.e.
Current GET:
api.local/api/v2_agent_properties/83.json
Target GET:
api.local/api/v2_agent_properties(83)
you could set this in the beforeRender of the appController:
$this->RequestHandler->renderAs($this, 'json');