DOOMer / screengrab

Crossplatform tool for fast making screenshots.
http://screengrab.doomer.org/
GNU General Public License v2.0
23 stars 8 forks source link

Add MediaCrush api support #27

Closed jleclanche closed 10 years ago

jleclanche commented 10 years ago

https://mediacru.sh

Very promising and open source service. Strongly recommend adding it.

jleclanche commented 10 years ago

Instructions here, full docs to follow

https://github.com/MediaCrush/MediaCrush/issues/50#issuecomment-22433960

ddevault commented 10 years ago

Full docs https://mediacru.sh/docs/

DOOMer commented 10 years ago

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) :(

jleclanche commented 10 years ago

I think you're supposed to send as json.

eXeC64 commented 10 years ago

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.

DOOMer commented 10 years ago

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());
jdiez17 commented 10 years ago

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?

DOOMer commented 10 years ago

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 -
jdiez17 commented 10 years ago

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?

jdiez17 commented 10 years ago

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.

DOOMer commented 10 years ago

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.

jdiez17 commented 10 years ago

Can you post a wireshark dump of your request?

DOOMer commented 10 years ago

http or https?

jdiez17 commented 10 years ago

https. Also, make sure the requests you make to mediacru.sh are using SSL, not just plain HTTP.

DOOMer commented 10 years ago

Tomorrow. Just now is not set decrypting SSL traffic with Wireshark on my machine.

jdiez17 commented 10 years ago

You can send the request using http, just to see what you're sending.

DOOMer commented 10 years ago

https://gist.github.com/DOOMer/6623942

jdiez17 commented 10 years ago

"Malformed packet: mime multipart"

DOOMer commented 10 years ago

This is not right, should it be otherwise?

jdiez17 commented 10 years ago

Well, the multipart packet should be properly formed, of course. What do you mean?

DOOMer commented 10 years ago

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 :(

ddevault commented 10 years ago

You should be letting a library do all this for you. Why are you manually constructing HTTP requests?

DOOMer commented 10 years ago

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.

DOOMer commented 10 years ago

Test https://mediacru.sh/PwHJMkfS8eHE

jdiez17 commented 10 years ago

That worked! What was it?

DOOMer commented 10 years ago

Now, instead manually constructing HTTP requests, I use QHttpMultiPart. Earlier, I just forgot about this class in Qt 4.8.

jdiez17 commented 10 years ago

Fair enough. The code looks fine now. Good job! :thumbsup:

jleclanche commented 10 years ago

Tested, works fine. Thank you!

Could you add the delete url once you take care of #17? It's just /delete, easy enough to autogenerate.

DOOMer commented 10 years ago

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.