Equivalent of URLDownloadToFile for JSON - c++

URLDownloadToFile downloads the HTML data of the URL but I have a URL that has JSON data. Is there a function that I can use to download the data in the JSON URL?
ie. How can I download the data in this JSON URL .

I am not sure whether there is a built-in function to do so. But I believe JsonCpp may help you to parse json data.

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

flask upload file API without filename

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".

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

How to distinguish between a data uri and an image url?

I have a php script that handles the url sent to it via ajax from a js file. This is either a data uri or an image url. What would be the best way to distinguish whether the string supplied is a data uri or an image url, from the php script. I was thinking of using a regex to test the data uri. But i dont seem to come with a right regex that can handle the data uri.
Well... if it starts with data: then it's a data URL. So... if( substr($url,0,5) == "data:") should do it.
Remember: KISS.
Check the extension of the URL.
Regex: \.[^\.]*$

HTTP Json requests in C++?

How to make HTTP Json requests in C++? Any library? Under "HTTP Json request" I mean make POST with Json object as data and receive result as Json.
Use libCURL to get the actual JSON data. Then parse it with some C++ library like jsoncpp.