I'm doing a file upload using https://github.com/danialfarid/ng-file-upload but I don't understand whether I'm actually sending the file or not. The payload just says:
------WebKitFormBoundaryaym16ehT29q60rUx
Content-Disposition: form-data; name="file"; filename="webfonts.zip"
Content-Type: application/zip
------WebKitFormBoundaryaym16ehT29q60rUx--
I don't understand what this means? It sort of looks like its being uploaded but the POST comes back instantly and I expected to see some sort of file stream. Whats going on, am I sending the file or not?
The boundary is included to separate name/value pair in the multipart/form-data . The boundary parameter acts like a marker for each pair of name and value in the multipart/form-data. The boundary parameter is automatically added to the Content-Type in the http (Hyper Text Transfer Protocol) request header.
Multipart form data: The ENCTYPE attribute of <form> tag specifies the method of encoding for the form data. It is one of the two ways of encoding the HTML form. It is specifically used when file uploading is required in HTML form. It sends the form data to server in multiple parts because of large size of file.
A boundary is just the 'key' to separate the multiple "parts" of a multipart payload. Normally something like '&' is enough to separate the variables but you need something more unique to separate the payloads within the payload.
Each item in a multipart message is separated by a boundary marker. Webkit based browsers put "WebKitFormBoundary" in the name of that boundary.
The Network tab of developer tools do not show file data in a multipart message report: They can be too big.
Use a tool like Charles Proxy to watch the request instead if you want to monitor exactly what is in there.
That is the payload of the temporary image or document in post method. You can access the above code using php.
<?php
print_r($_FILES); // to print the file type params
$target_dir = "/var/www/html/me_docs/";
$date = date_create();
$timestamp = date_timestamp_get($date);
$filename = pathinfo($_FILES["filepond"]["name"],PATHINFO_FILENAME);
$extension = pathinfo($_FILES["filepond"]["name"],PATHINFO_EXTENSION);
$fullname = $filename.'_'.$timestamp.'.'.$extension;
$target_file_name = $target_dir.$fullname;
if(move_uploaded_file($_FILES["filepond"]["tmp_name"], $target_file_name))
{
echo "moving file success";
}
else
{
echo "failed moving file";
}
I hope it is useful for someone, Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With