I am trying to upload a file using a form with Dajax.
I use serializeObject to serialize data with JavaScript. However, an input with a file type is not serialized before it sends to the server. Is there any way to upload a file using Dajax?
Related
I am trying to upload a file to the Shared Documents library of my SharePoint website. The files are of type PDF and HTML. I am running a Cold Fusion development environment and using CFHTTP commands to execute HTTP requests. I have been able push a POST command and a PUT command to the proper endpoints listed on this link below:
Link: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#best-practices
I do not understand why but the first section that mentions the HTTP requests for creating an upload session is different than what was used in the example a little further. For my project, I am using the endpoint:
"/{variables.instance.microsoftGraphAPIURL}/drive/root:/{item-path}:/createUploadSession"
P.S. variables.instance.microsoftGraphAPIURL is a variable to a microsoft graph endpoint to our Sharepoint website
With better luck using PUT commands than POST commands for creating an Upload Session. I am able to receive an uploadURL, but the issue comes with trying to upload the file. For the file upload, I am trying to upload a file in the same directory with a file size of 114992 bytes. I keep getting "The Content-Range header length does not match the provided number of bytes." whenever I run my Put command to upload the file.
Thus, my Content-Range is "bytes 0-114991/114992" and my Content-Length is "114992". For the image below, I replaced the file with a pdf, but the original file was an HTML page at 114992 bytes. I want to use a resumable upload session to have one function for uploading image, HTML, and PDF files.
If anyone could tell me if there is an issue with my content headers or my upload session http request or anything else that is causing my issue, that would be amazing! Thank you.
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
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".
My Application requires client to upload a Huge file through a Form . Currently , django stores the file in temp folder and my view function gets hit only after the whole file is uploaded where i can access the file.
My requirement is to be able to get uploaded chunks as soon as they arrive at the server so that i can start the processing .
I checked , there is streaming HTTP response but nothing for HTTP request (POST from client)
Thanks
I have a web app build with pyramid. One of the endpoints /foo is connected to the method foo(request):
def foo(request):
file = request.POST['my_file'].file
...do stuff with file...
I then send a file to the endpoint using postman. The problem is, the file is opened as a BufferedRandom in binary mode, but I need to manipulate the file in text mode. Is it possible to do this?
Found my answer here: Not able to parse a .csv file uploaded using Flask
In my case I added
stream = io.StringIO(file.read().decode("utf8"), newline=None)
and was able to manipulate stream