jgravois's avatar

Upload to DigitalOcean Spaces - Strange Destination

I am uploading a file to DO Spaces using this code with the data-points of (id: 650, doc: 'shop_report')

public function doc_upload(Request $request)
    {
        $file = $request->file('file');
        $id = $request->id;
        $doc = $request->doc;
        $ext = $file->getClientOriginalExtension();

        $fileName = $doc . '.' . $ext;
        $upload_success = Storage::disk('spaces')
            ->putFileAs("RMA/{$id}/$file", $file, $fileName, 'public');

        if ($upload_success) {
            $rma = ReturnsRequest::whereId($id)->first();
            $rma[$doc] = $fileName;
            $rma->save();

            return $rma;
        } else {
            return response()->json('error', 419);
        } // end if
    } // end function

On Spaces, I get the following structure:

650
    private
        var
            tmp
                phpUaKP8q
                    shop_report.pdf

Any insight is welcome.

0 likes
3 replies
click's avatar
click
Best Answer
Level 35

What is the expected output? Because your variable $file is not a string, it is an UploadedFile object that is turned into a string which probably causes the private/var/tmp/phpUaKP8q path.

jgravois's avatar

My expected outcome is for the file to be at

650 shop_report.pdf

so, I need to manipulate $file to achieve that?

jgravois's avatar

$upload_success = Storage::disk('spaces')->putFileAs("RMA/{$id}/", $file, $fileName, 'public');

(red faced)

Please or to participate in this conversation.