Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers sending a picture in a form #55

Closed
yosmanyga opened this issue May 21, 2012 · 9 comments
Closed

Headers sending a picture in a form #55

yosmanyga opened this issue May 21, 2012 · 9 comments

Comments

@yosmanyga
Copy link

I'm submitting a form with a picture. Using a browser I get this:

Content-Disposition: form-data; name="picture"; filename="thepicture.jpg"
Content-Type: image/jpeg

But using guzzle I get this:

Content-Disposition: form-data; name="picture"; filename="C:\Windows\Temp\uplC14D.tmp"
Content-Type: application/octet-stream

Any bug here?

@mtdowling
Copy link
Member

Can you provide some example code?

@yosmanyga
Copy link
Author

require_once 'guzzle.phar';

$client = new \Guzzle\Http\Client();
$request = $client->post('post.php')
    ->addPostFiles(array(
        'picture' => 'path/to/image.jpg'
    ));
$response = $request->send();

@yosmanyga
Copy link
Author

A comment related to the full path: http://www.php.net/manual/en/function.curl-setopt.php#101231

And a comment about content-type: http://www.php.net/manual/en/function.curl-setopt.php#97591

@mtdowling
Copy link
Member

Interesting. You'll need to set the Content-Type yourself, but I'm not sure what's going on with the Content-Disposition header. I wonder if that's an issue with curl or an implementation detail in Guzzle. I'll need to find some time to investigate further.

@yosmanyga
Copy link
Author

Well, using a normal browser, users don´t need to set the Content-Type for their upload files. So Guzzle should detect Content-Type too.

@mtdowling
Copy link
Member

There's some Content-Type guessing functionality that I suppose I could refactor so that it attempts to guess the content-type for POST uploads: https://github.com/guzzle/guzzle/blob/master/src/Guzzle/Http/EntityBody.php#L110

I'm not sure why you're getting a reference to a temp file. I'll look into that sometime this week. However, I don't think it would be an issue to send the full path to a file. The chdir method in the comment you referenced would not work if you were submitting multiple files in different directories.

@yosmanyga
Copy link
Author

Cool, it would be nice to have the auto-detecting.

According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html (19.5.1 Content-Disposition):

The receiving user agent SHOULD NOT respect any directory path information present in the filename-parm parameter, which is the only parameter believed to apply to HTTP implementations at this time. The filename SHOULD be treated as a terminal component only.

An example is
Content-Disposition: attachment; filename="fname.ext"

More here: http://www.ietf.org/rfc/rfc1806.txt (2.3 The Filename Parameter)

@robertkraig
Copy link

I'm running into the same issue as @yosmanyga did originally. The filename is getting sent with it's full path to the server, and this is not correct. It should only display the file selected to be uploaded. Anyways, I'm sure I have the newest cost since I get this via composer. What gives?

@mtdowling
Copy link
Member

Found a way to workaround this with cURL. The master branch has a fix for this now and will strip out the leading slash on the filename portion of the Content-Disposition header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants