-
Notifications
You must be signed in to change notification settings - Fork 299
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
Upload feature #89
Upload feature #89
Conversation
Thanks @dtelaroli! Hope to finishing reviewing this this weekend! |
How to add mime type of the file? |
The mime you have on server side. Eg. $_FILE['nameOfFile']['type'] The upload no need to know the mime type, only the name on the disk (including temp file). |
I have to send POST with content-type multipart/form-data and this sample payload:
With Guzzle I get the right answer:
With HTTPful I can't specify content-type of files and this fails and API complains about wrong request body:
I just don't see any other difference. Guzzle allows to add files mime types that are in the sample payload. |
application/json is not a file the Content-Type to send files is multipart/form-data maybe you should send file in other request or send json as string |
try this:
this:
or this:
you will receive in server a $_FILES and $_POST data |
I don't have access to server side. It's some company API. Example client in javascript appends json in Blob object:
Taking that under consideration I created in PHP a temporary file with my json:
and attached it as file with content-type as shown in code attached earlier. My request looks like the one from example and also shown above. And finally I receive a proper response from API server. I can do it in Guzzle but I was looking for a way to do it in HTTPful. The rest of API works great but I will have to rewrite everything to Guzzle because of this one request. Guzzle has an option to add file mime, without that it returns the same responseError as HTTPful. With mime everything works fine. Looks like with HTTPful I can't go as far. Thanks for your answers. |
The attach method not accept file, the parameter should be path to file Why you not send data as json???
This module to AngularJs work for me to upload files and data as json: https://github.com/danialfarid/angular-file-upload/blob/master/angular-file-upload.js#L86. Have you sure that file upload from FormData to PHP work, before the Httpful request? PS: The upload feature is new, and it is very simple, so, if you need extra features like a Guzzle, open a issue and wait or send pull request. |
To be precise it is a temporary path to temporary file. So parameter is ok. I can't change what server does to my request. If it requires request build this way I have to comply. I also would do it differently if I could. FormData sends straight to API, and I'm rewriting this in PHP for my app, they are two, not related apps. Now I know that this feature is simpler than I thought. Thank you for clarification. |
Implemented basic feature to upload files.
Use:
\Httpful\Request::post($this->url)
->body(array())
->attach(array('indexToPost' => '/path/to/file'))
->send()
The content type should be multipart/form-data
Method should be POST
Data should be array