Closed jleclanche closed 10 years ago
Instructions here, full docs to follow
https://github.com/MediaCrush/MediaCrush/issues/50#issuecomment-22433960
Full docs https://mediacru.sh/docs/
I'm tried add MediaCrus api support (upload files), but service returns 400 errror (bad request) on the my request (send data as content-type: multipart/form-data) :(
I think you're supposed to send as json.
It's fairly easy to use MediaCrush:
curl -F file=@/path/to/img.png https://mediacru.sh/api/upload/file
That line is taken from an upload script I use myself. Just make sure you're using https and the right content-type.
I use htps. And I had tested upload file via curl and saw his headers,
I add this headers to my request:
_request.setRawHeader("Host", "mediacru.sh");
_request.setRawHeader("Content-Type", "multipart/form-data; boundary=" + boundary(true));
_request.setRawHeader("Accept", "*/*");
_request.setRawHeader("User-Agent", "curl/7.32.0");
_request.setRawHeader("Content-Length", QByteArray::number(imageData.length()));
_request.setRawHeader("Expect", "100-continue");
and create uploading data^
uploadData.append(boundary());
uploadData.append("content-disposition: ");
uploadData.append("file; name='file'; ");
uploadData.append("filename='" + _uploadFilename + "'\r\n");
if (_formatString == "jpg")
{
uploadData.append("Content-Type: image/jpeg\r\n");
}
else
{
uploadData.append("Content-Type: image/" + _formatString + "\r\n");
}
uploadData.append("\r\n");
uploadData.append(imageData);
uploadData.append("\r\n");
uploadData.append(boundary());
Hello, MediaCrush programmer here. It's strange that you're getting a 400 from /api/upload/file
, it shouldn't return that status code. Unless you mean you're getting a 415?
Hello, jdiez17. No, I not get JSON with result error code, I getting HTML document with "Bad request" message.
This is a output server answer, which i getting instead JSON result.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
ANd i have "Error downloading http://mediacru.sh/api/upload/file - server replied: BAD REQUEST" error message in resopnse object in my app, instead empty string.
Also I installed MediaCrush on my PC, and test on it. And I getting in console:
127.0.0.1 - - [18/Sep/2013 16:45:20] "POST /api/upload/file HTTP/1.1" 400 -
Huh, that is strange. I fired up Wireshark and uploaded a file using PyCrush and here's the request I captured: https://mediacru.sh/RwKJ9zUH94DL
Can you capture yours?
Ah, I see. Your content disposition has to be form-data
, it looks like you're setting it to file
. Maybe changing that would help.
Wireshark screen, with analyse my POST request http://i.imgur.com/2kw8pK1.jpg
Ah, I see. Your content disposition has to be form-data, it looks like you're setting it to file. Maybe changing that would help.
No any effects.
Can you post a wireshark dump of your request?
http or https?
https. Also, make sure the requests you make to mediacru.sh are using SSL, not just plain HTTP.
Tomorrow. Just now is not set decrypting SSL traffic with Wireshark on my machine.
You can send the request using http, just to see what you're sending.
"Malformed packet: mime multipart"
This is not right, should it be otherwise?
Well, the multipart packet should be properly formed, of course. What do you mean?
I not understand properly or not properly formed packet in my POST request :(
And i don't know as the multipart packet should be properly formed :(
You should be letting a library do all this for you. Why are you manually constructing HTTP requests?
Why are you manually constructing HTTP requests?
Because by design Qt requires the creation of the request object manually, and does not create it automatically when you send a request from the QNetworkAccessManager. object.
Now, I think that my current code (shown above) can be changed a little and everything will work properly later today I will check it out.
That worked! What was it?
Now, instead manually constructing HTTP requests, I use QHttpMultiPart. Earlier, I just forgot about this class in Qt 4.8.
Fair enough. The code looks fine now. Good job! :thumbsup:
Tested, works fine. Thank you!
Could you add the delete url once you take care of #17? It's just
Fair enough. The code looks fine now. Good job!
Thanks :)
Could you add the delete url once you take care of #17?
Yes. I add it today after some hours.
https://mediacru.sh
Very promising and open source service. Strongly recommend adding it.