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

fails to create UploadedFile instance for AJAX PATCH/PUT requests using FormData JS API on file method for $request object (Possible Solution Proposition) #22967

Closed
isocroft opened this issue Jan 31, 2018 · 4 comments

Comments

@isocroft
Copy link

isocroft commented Jan 31, 2018

  • Laravel Version: 5.5.0
  • PHP Version: 7.0.0
  • Database Driver & Version: MySQL 5.3

Description:

I'm sure this can be added to the Symphony Core as part of the file method API for the Laravel Request object. There has been a long thread up until November last year about this issue. Well, this issue log is to present a long lasting solution that works. This issue has to do with the fact that Laravel lacks the ability to properly parse and extract data from a PUT/PATCH request stream for file uploads

Is there a way i can modify the core code to include this piece of code ?

If there is a way, i am willing to send in a pull request for this promptly. The gist code (see link) above was posted by @devmycloud

Steps To Reproduce:

var file_input = document.querySelector('.document[type="file"]');

file_input.addEventListener('change', function(e){
 
      var xhr = new XMLHttpRequest, formdata = new FormData, file = e.target.files[0];

     xhr.open('PUT', 'http://localhost:4000/upload', false);

     formadata.append('document', file);

     xhr.onreadystatechange = function(e){
             if(e.type == 'load'){
                    console.log(this.responseText);
             }else if(e.type == 'readystatechange' && this.readyState == 4){
                   if(this.status === 200){
                           console.log(this.responseText);
                   }
             }
    };
    
     xhr.send(formdata);

}, false);
      Route::put('upload', 'UploadsController@doUpload');
class UploadsController extends Controller {

       # Assuming this to be a Laravel Controller at the '/upload' route
       # URL: http://localhost:4000/upload

        public function doUpload (Request $request){

                  return response()->json($request->file('document')); 
                  # return response()->json($request->document);
                  # return response()->json($request->all());                

                 //  all above prints an empty upload object to the screen
         }
}

The code above reproduces the issue

@sisve
Copy link
Contributor

sisve commented Jan 31, 2018

It would be highly relevant to give us a ling to the thread you're talking about, and perhaps add some steps to reproduce.

@themsaid
Copy link
Member

themsaid commented Jan 31, 2018

Please complete the issue report template, this issue is missing Steps to Reproduce.

@isocroft isocroft changed the title fails to extract UploadedFile instance for AJAX POST/PUT REQUESTS USING FORMDATA API (Possible Solution) fails to create UploadedFile instance for AJAX PATCH/PUT requests using FormData JS API on file method for $request object (Possible Solution Proposition) Feb 1, 2018
@isocroft
Copy link
Author

isocroft commented Feb 1, 2018

@sisve here is the link to the issue I'm referencing -> LINK. I'm up for solutions and not debates. The issue i have confirmed is from Symphony. I just wanted to confirm if a PR to the Symphony project will mean that Laravel gets the issue solved.

OR if the Symphony Core Team won't accept my PR, can this be built into the Core of Laravel (possibly inside the Request class)

@themsaid
Copy link
Member

themsaid commented Feb 1, 2018

Please open a PR with your suggested changes.

@themsaid themsaid closed this as completed Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants