duna-oss/flystorage

Add support for pre-signed upload URL

Opened this issue · 4 comments

The temporaryUrl() method will only return a GET request for an existing file resource you'd like to make a limited-time URL for. At least with the AWS implementation of this method it uses the @aws-sdk/s3-request-presigner package, which does support creating temporary upload URLs by using PutObjectCommand() instead of GetObjectCommand().

At this point, it's not clear if the Flystorage API you have in mind should use temporaryUrl() and just add the HTTP method to the options parameter, or if you would prefer a separate dedicated function for pre-signed upload URLs.

Happy to help implement this, but need some guidance on your API concerns.

@selfsimilar I'm happy to discuss. The reason why I haven't implemented this is because apart from it being a URL, it's very difficult to abstract. As in, the parameters are all different across implementations and what you do with the URL after receiving it is also different and requires specific handling. At least, that's my interpretation of the situation. If an API for this lands in Flystorage there needs to be some common ground between the various adapters. At a minimum it needs to be usable across the majority of the major providers (AWS/Azure/GCP). Again, happy to see if we can find something.

I agree that this requires a more comprehensive review of the various platforms' implementations. My guess is that the input parameter side should be relatively easy to solve, in that there's probably a fixed set of total possible parameters across all providers, and it's probably sufficient to use defaults that can be thrown away if not needed by a particular provider. The output side and usage of the output definitely is trickier, and may indicate that these shouldn't be lumped together, for example if doing so effectively converts temporaryUrl() into a multi-tool method. This isn't a high priority for me ATM, but I'll happily put some time in to cataloguing the major providers' inputs and outputs for creating upload Urls/tokens. Hopefully getting a lay of the land will make it clearer if this is functionality that benefits from an abstraction layer.

@frankdejonge what about having a method similar to what Laravel uses for its Storage provider built atop of flysystem?
https://laravel.com/docs/11.x/filesystem#temporary-upload-urls

use Illuminate\Support\Facades\Storage;
 
['url' => $url, 'headers' => $headers] = Storage::temporaryUploadUrl(
    'file.jpg', now()->addMinutes(5)
);

I am not sure if other cloud providers can be abstracted in a similar fashion though, but would be great to have a simple method like that.

@ggolda the laravel solution only works for S3, in which case it's better to only simplify that case. We can look into mechanism how other implementations can be supported as well, or even how we might provide a express/http polyfill, but it's difficult not to build the wrong abstraction.