zerraph's avatar

Storage::putFile without default disk

From my understanding, Storage::putFile is used to upload a file directly to a service such as s3 as opposed to moving it through the web server. However, Storage::disk('s3')->putFile() seems to be invalid. If I want to upload to a non-default disk, I need to use Storage::disk('s3')->put() instead.

Is there a workaround to this, or am I stuck having to save to the default disk if I want to directly upload to s3?

0 likes
12 replies
Sinnbeck's avatar

What error are you getting? I see no mention of this being invalid

1 like
Sinnbeck's avatar

@zerraph I need to check that. This quote from the docs makes it seem possible

The putFile and putFileAs methods also accept an argument to specify the "visibility" of the stored file. This is particularly useful if you are storing the file on a cloud disk such as Amazon S3

1 like
zerraph's avatar

@Sinnbeck To be clear, I can save files to s3. I am just having to use s3 as my default disk and use the Storage::putFile method. This means, however, that I wouldn't be unable to use putFile if I wanted to also have a different disk that isn't the default.

So in summary, Storage::putFile (which will save to the default disk) seems valid. And Storage::disk('s3')->putFile seems invalid.

Snapey's avatar

@zerraph Storage::disk() returns a contract, which is resolved by the container to Illuminate\Filesystem\FilesystemManager

1 like
zerraph's avatar

@Snapey Interesting. After more testing, I got it to work as well. I'm still getting the error from VS Code, though. That's very confusing to me, but I do appreciate your insights. Thank you very much.

Snapey's avatar

@Sinnbeck sometimes you need to run the command in vscode to refresh the indexes

Sinnbeck's avatar

@Snapey ah good to know. Don't use vscode for php but it's a great tip 👍

Please or to participate in this conversation.