mardi 2 janvier 2018

Laravel Uploading File - Creating default object from empty value

I seem to be getting an error in what I assume is in relation to me uploading a file.

Here is my controller:

public function scannerUpload(Request $request){
    $requestFile = request('RemoteFile');
    $path = Storage::putFile('public/shipments', new File(request('RemoteFile')));
        Shipment_Attachment::create([
                         $Shipment_Attachment->attachmentPath = $path,
                         $Shipment_Attachment->attachmentBody = request('Description'),
                         $Shipment_Attachment->attachmentVisibility = request('Visibility'),
                         $Shipment_Attachment->attachmentDate = request('Date'),
                         $Shipment_Attachment->attachmentType = request('Type'),
                         $Shipment_Attachment->attachmentLong = request('Longitude'),
                         $Shipment_Attachment->attachmentLat = request('Latitude'),
                         $Shipment_Attachment->shipment_id = request('ShipmentID'),
                         $Shipment_Attachment->user_id =>  Auth::id()
                    ]);  
    return response()->json($request);
    }

Now I get an error at this line: $Shipment_Attachment->attachmentPath = $path,

But I'm wondering if maybe I'm not uploading and requesting the file correctly. When I post the file, this is what the parameters look like after I click my upload button:

-----------------------------54701348911009
Content-Disposition: form-data; name="Date"

2018-01-02
-----------------------------54701348911009
Content-Disposition: form-data; name="Visibility"

1
-----------------------------54701348911009
Content-Disposition: form-data; name="Type"

1
-----------------------------54701348911009
Content-Disposition: form-data; name="Description"

This is a Description
-----------------------------54701348911009
Content-Disposition: form-data; name="Latitude"

39.777541
-----------------------------54701348911009
Content-Disposition: form-data; name="Longitude"

-104.94250199999999
-----------------------------54701348911009
Content-Disposition: form-data; name="shipmentID"

32109829
-----------------------------54701348911009
Content-Disposition: form-data; name="RemoteFile"; filename="test-pod.pdf"
Content-Type: application/octet-stream

%PDF-1.5
1 0 obj
<<
/Creator ()
/CreationDate (20180102192642)
/ModDate (20180102192642)
/Author ()
/Producer () and so on and so on for another hundred lines

So am I correct in how I am handling the upload of the file or should it be handled differently?

Thanks! Matt



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DR4O3e
via IFTTT

Aucun commentaire:

Enregistrer un commentaire