1

I am building a web service for mobile application using Laravel. I need to let the users to upload images. I am using passport package. In developing environment I created a function store as follows

public function store(Request $request)
{
    return $request;
}

and using Firefox poster I post contents. These are the parameters

enter image description here

enter image description here

The problem is the function store always returns empty array while I expect it to return information about the file. What is wrong here?

thanks

2 Answers 2

4

I found it. Firefox Poster has problems with this. I used Chrome Postman. I removed all the headers and set a key for file. as follows

enter image description here

it is header

enter image description here

and this is the code

public function store(Request $request)
{
    $file = $request->file('image');
    return $file->getClientOriginalExtension();
}
Sign up to request clarification or add additional context in comments.

Comments

2

Returning $request will not work. If you want to check if the file exists, try return $request->allFiles()

3 Comments

Does it display an empty array?
yes. an empty array is returned, Is there any problem with the headers?
yes, it's not reaching the backend. Probably best to try sending a file using a FormData object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.