File is missing when trying to upload a model through API doing a PUT request - Multipart/form-data Requests...
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm using Laravel for the backend for an Android app.
I want to update the user picture, but when uploading the file + additional data to my backend, the file is missing in the request:
dd($request->hasFile('avatar')); // false
dd($request->File('avatar')); // null
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer {{token}}
Content-Type: multipart/form-data
// Body of the request
'avatar' -> the image (in postman)
This is some of my update method, the part that manage the file:
public function update(Request $request)
{
// ...
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save('/path/' . $filename));
$user->avatar = $filename;
}
// ...
$user->save();
// ...
}
I don't know what am I doing wrong. Thanks in advance.
php laravel api laravel-5 file-upload
add a comment |
I'm using Laravel for the backend for an Android app.
I want to update the user picture, but when uploading the file + additional data to my backend, the file is missing in the request:
dd($request->hasFile('avatar')); // false
dd($request->File('avatar')); // null
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer {{token}}
Content-Type: multipart/form-data
// Body of the request
'avatar' -> the image (in postman)
This is some of my update method, the part that manage the file:
public function update(Request $request)
{
// ...
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save('/path/' . $filename));
$user->avatar = $filename;
}
// ...
$user->save();
// ...
}
I don't know what am I doing wrong. Thanks in advance.
php laravel api laravel-5 file-upload
Can you tryvar_dump
on$request->all()
Maybe your file wasn't sent properly?
– shalvah
Jun 21 '17 at 21:50
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
1
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
1
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
1
Try usingPOST
instead ofPUT
method
– Pankaj Makwana
Jun 22 '17 at 5:33
add a comment |
I'm using Laravel for the backend for an Android app.
I want to update the user picture, but when uploading the file + additional data to my backend, the file is missing in the request:
dd($request->hasFile('avatar')); // false
dd($request->File('avatar')); // null
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer {{token}}
Content-Type: multipart/form-data
// Body of the request
'avatar' -> the image (in postman)
This is some of my update method, the part that manage the file:
public function update(Request $request)
{
// ...
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save('/path/' . $filename));
$user->avatar = $filename;
}
// ...
$user->save();
// ...
}
I don't know what am I doing wrong. Thanks in advance.
php laravel api laravel-5 file-upload
I'm using Laravel for the backend for an Android app.
I want to update the user picture, but when uploading the file + additional data to my backend, the file is missing in the request:
dd($request->hasFile('avatar')); // false
dd($request->File('avatar')); // null
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer {{token}}
Content-Type: multipart/form-data
// Body of the request
'avatar' -> the image (in postman)
This is some of my update method, the part that manage the file:
public function update(Request $request)
{
// ...
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save('/path/' . $filename));
$user->avatar = $filename;
}
// ...
$user->save();
// ...
}
I don't know what am I doing wrong. Thanks in advance.
php laravel api laravel-5 file-upload
php laravel api laravel-5 file-upload
edited Jan 4 at 4:58
HCK
asked Jun 21 '17 at 21:46
HCKHCK
3,81011338
3,81011338
Can you tryvar_dump
on$request->all()
Maybe your file wasn't sent properly?
– shalvah
Jun 21 '17 at 21:50
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
1
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
1
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
1
Try usingPOST
instead ofPUT
method
– Pankaj Makwana
Jun 22 '17 at 5:33
add a comment |
Can you tryvar_dump
on$request->all()
Maybe your file wasn't sent properly?
– shalvah
Jun 21 '17 at 21:50
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
1
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
1
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
1
Try usingPOST
instead ofPUT
method
– Pankaj Makwana
Jun 22 '17 at 5:33
Can you try
var_dump
on $request->all()
Maybe your file wasn't sent properly?– shalvah
Jun 21 '17 at 21:50
Can you try
var_dump
on $request->all()
Maybe your file wasn't sent properly?– shalvah
Jun 21 '17 at 21:50
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
1
1
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
1
1
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
1
1
Try using
POST
instead of PUT
method– Pankaj Makwana
Jun 22 '17 at 5:33
Try using
POST
instead of PUT
method– Pankaj Makwana
Jun 22 '17 at 5:33
add a comment |
1 Answer
1
active
oldest
votes
After some research, I could make it work but using a POST
Request adding _method = PUT
as param (http://www.someurl.dev?_method=PUT
).
PUT request with files aren't handle properly -if i'm not wrong- on purpose
Anyway, is not the solution that I was looking.. but at least work.
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was usingPUT
and trying to upload for almost 24 hours!! Then finally I changed toPOST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.
– Noitidart
Jan 19 '18 at 6:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44686797%2ffile-is-missing-when-trying-to-upload-a-model-through-api-doing-a-put-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After some research, I could make it work but using a POST
Request adding _method = PUT
as param (http://www.someurl.dev?_method=PUT
).
PUT request with files aren't handle properly -if i'm not wrong- on purpose
Anyway, is not the solution that I was looking.. but at least work.
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was usingPUT
and trying to upload for almost 24 hours!! Then finally I changed toPOST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.
– Noitidart
Jan 19 '18 at 6:59
add a comment |
After some research, I could make it work but using a POST
Request adding _method = PUT
as param (http://www.someurl.dev?_method=PUT
).
PUT request with files aren't handle properly -if i'm not wrong- on purpose
Anyway, is not the solution that I was looking.. but at least work.
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was usingPUT
and trying to upload for almost 24 hours!! Then finally I changed toPOST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.
– Noitidart
Jan 19 '18 at 6:59
add a comment |
After some research, I could make it work but using a POST
Request adding _method = PUT
as param (http://www.someurl.dev?_method=PUT
).
PUT request with files aren't handle properly -if i'm not wrong- on purpose
Anyway, is not the solution that I was looking.. but at least work.
After some research, I could make it work but using a POST
Request adding _method = PUT
as param (http://www.someurl.dev?_method=PUT
).
PUT request with files aren't handle properly -if i'm not wrong- on purpose
Anyway, is not the solution that I was looking.. but at least work.
answered Jun 22 '17 at 3:56
HCKHCK
3,81011338
3,81011338
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was usingPUT
and trying to upload for almost 24 hours!! Then finally I changed toPOST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.
– Noitidart
Jan 19 '18 at 6:59
add a comment |
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was usingPUT
and trying to upload for almost 24 hours!! Then finally I changed toPOST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.
– Noitidart
Jan 19 '18 at 6:59
1
1
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was using
PUT
and trying to upload for almost 24 hours!! Then finally I changed to POST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.– Noitidart
Jan 19 '18 at 6:59
Oh my gosh this was soooo the problem I was having and I didnt even realize it. I was using
PUT
and trying to upload for almost 24 hours!! Then finally I changed to POST
and it worked! Thanks for this question and solution! i actually upvoted a couple days ago but forgot to put this comment.– Noitidart
Jan 19 '18 at 6:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44686797%2ffile-is-missing-when-trying-to-upload-a-model-through-api-doing-a-put-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you try
var_dump
on$request->all()
Maybe your file wasn't sent properly?– shalvah
Jun 21 '17 at 21:50
@shalvah It return empty. Now, i'm trying doing this in a POST request and it works. The PUT method seems to be the problem.
– HCK
Jun 21 '17 at 22:29
1
Oh. You never mentioned that it was PUT. I'm not sure files are meant to be uploaded with PUT, and even if they are, they may not automatically get parsed into the request body by Laravel.
– shalvah
Jun 21 '17 at 22:33
1
Yeah, it seems to be and old -and unresolved- issue of Symphony according to this: github.com/laravel/framework/issues/13457
– HCK
Jun 21 '17 at 22:43
1
Try using
POST
instead ofPUT
method– Pankaj Makwana
Jun 22 '17 at 5:33