flask upload file API without filename - flask

The file upload API requires the specification of filename. Is there an example of the flask API that just post the file content with the filename?
https://flask.palletsprojects.com/en/1.1.x/patterns/fileuploads/

You have to inspect the "Request" class! https://flask.palletsprojects.com/en/1.1.x/api/#flask.Request

You don't have to use the file name in your Flask endpoint if you don't want to, just process the data you need. You have few different ways to access the data with Request object, depending on how you sent the data to server:
use request.files if you will send the file through some HTML form or using -F flag with curl.
use request.data to read raw data as string in case mimetype can not be handled by Flask/Werkzeug (e.g. no Content-Type header).
use request.get_data() to read buffered data as a bytestring (e.g. when you use -d flag with curl).
use request.stream if the incoming form data is not encoded with known mimetype, although docs say that "Most of the time it is a better idea to use data which will give you that data as a string".

Related

How to upload a file from a URL as multipart/form-data in Postman

I have an API endpoint that accepts multipart/form-data file upload. I managed to upload a local file to it with Postman using the File option as below:
Now how can I upload a file that is hosted at a given URL using Postman without manually downloading it and then selecting its filename as in the above screenshot? I'm hoping to somehow GET the URL, store the binary data, and upload to the endpoint, all within a Postman collection.
One of the answers from Postman community issue:
Using Postman’s pre-request script:
Download the content from URL
Convert it to binary
Assign the binary value to a dynamic variable
Use the variable within your request

Qmetry - How to save soap api response to xml file

In Qmetry, I am calling below soap api request.
user requests 'post.sample.call'
Want to save the response in a xml file (sample.xml). Save response to "sample.xml"
Is there a step in qmetry to achieve this?
If purpose to save response for later reference, you will be able to find it under command log tab in qaf report. If you want to validate response you can utilize methods available with qaf we service support library. For any other purpose if you want to write response to file use get response from test base and write to file. Below code will give you response to write in file.
String responseBody = new RestTestBase().getResponse().getMessageBody();

Flask unable to receive chunked data

I am kinda newby in python thus the question.
I am trying to create a simple http web server that can receive chunked data from a post request.
I have realized later that once a request sends a headers with chunked data, the Content-length headers will be set to zero, thus reading the sent data with 'request.get_data()' will fail.
Is there another way of reading the chunked data?
The request I receive does give me the data length in the 'X-Data-Length' headers.
Did you write both of the js upload file code and the flask in backend to handle upload request? If not then you will need some help with js to upload it.
One way to achieve chucked data upload is:
Chucked that file in the frontend with js. Give it some headers in the request for the total size, number of the chunk, chunk size... and send each chuck in a separate POST request (You can use dropzone.js for example, they will do the job for you, just need to config the params)
In the backend, create an upload API which will read the request headers and merge the file chunks back together

How to attach file to Postman environment?

How can I attach a file to the environment in order to launch the collection in the Postman collection runner? The file is attached to the form-data, and manually the request runs ok, but as soon as I run it in the collection runner, the runner doesn't see the file and the 500 Internal server error occurs. How can this issue be fixed?
Request BodySee the full detail in the link
While constructing requests, you’ll work frequently with the request body editor. Postman lets you send almost any kind of HTTP request. The body editor is divided into 4 areas and has different controls, depending on the body type.
Note about Headers: When you are sending requests through the HTTP protocol, your server might expect a Content-Type header. The Content-Type header allows the server to parse the body properly. For form-data and urlencoded body types, Postman automatically attaches the correct Content-Type header so you don’t have to set it. The raw mode header is set when you select the formatting type. If you manually use a Content-Type header, that value takes precedence over what Postman sets. Postman does not set any header type for the binary body type.
Form-data
form-data
multipart/form-data is the default encoding a web form uses to transfer data. This simulates filling a form on a website, and submitting it. The form-data editor lets you set key-value pairs (using the data editor for your data. You can attach files to a key as well. Note: due to restrictions of the HTML 5 spec, files are not stored in history or collections. You will need to select the file again the next time you send the request.
Uploading multiple files each with their own Content-Type is not supported yet.See the image here in the link

convert JSON input to form-data in AWS application gateway

Our old legacy APIs accept the data only in form-data format, but I am required to send my data as JSON in body of request. So, how I can convert my JSON (application/json) input to form data in AWS Application gateaway.
I have input parameter like this
{"key1": "val1", "key2": "val2"}
I tried many solution with template mapping and query string parameter but they didn't work for me maybe I am doing something wrong. Above configuration is fully supporting form-data.
Note: Due to some reason I don't want to change my legacy django code to handle JSON input instead of form data.
I would suggest looking at the structure of a raw POST form-data request. Then you should be able to structure the Integration Request to fit the form-data format using the right Content-Type and mapping template.
There is an example for GET and an example for POST on this page (with the caption "the HTTP request looks like this") https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data