fine-uploader icon indicating copy to clipboard operation
fine-uploader copied to clipboard

5 - Upload directly to Google Cloud Storage

Open engagingcomms opened this issue 10 years ago • 41 comments

I had a quick search to see if there was a tutorial for this but no luck. Is there a way to modify the server side script so that Fineuploader saves to Google Storage?

https://developers.google.com/appengine/docs/php/googlestorage/

This would be very handy.

engagingcomms avatar Mar 10 '14 21:03 engagingcomms

@engagingcomms You can send the files to whatever location you choose, as the server is entirely under your control. Fine Uploader is exclusively a client-side library. You can use Fine Uploader's traditional endpoint handler to send files to your specific server, where you can then relay the files to Google Storage using the GS API.

rnicholus avatar Mar 11 '14 04:03 rnicholus

Has anyone done this before / have some sample code? As I have no idea :)

engagingcomms avatar Mar 11 '14 04:03 engagingcomms

In particular with Google App engine you can't save locally at all, has to be direct to storage.

engagingcomms avatar Mar 11 '14 04:03 engagingcomms

It looks like GCS supports CORS, so it seems like we could upload directly to a bucket from the browser, à la Fine Uploader S3/Azure. Is this what you are wondering about?

rnicholus avatar Mar 11 '14 04:03 rnicholus

Yes that would be ideal. Upload to a Google Bucket with a unique file name, then return that filename to the Google APP. Not to sure where to start though.

engagingcomms avatar Mar 11 '14 04:03 engagingcomms

It's something we can look into directly supporting in a future release. Theoretically, it's possible without our intervention, but a specific Google Cloud Storage module for Fine Uploader would make it easier, so you don't have to worry about the details of the GCS API. We'll discuss this internally.

rnicholus avatar Mar 11 '14 04:03 rnicholus

Nice one cheers.

engagingcomms avatar Mar 11 '14 04:03 engagingcomms

We might be able to easily support this via the s3 compatibility layer provided by cloud storage.

rnicholus avatar Mar 26 '14 00:03 rnicholus

That would be awesome. The Google APP engine doesn't allow you to store directly to server so this would be a very valuable script.

engagingcomms avatar Mar 26 '14 00:03 engagingcomms

The work completed in #1332 may make this possible, assuming the Google Cloud Storage S3 integration layer is enabled. Any Google Cloud Storage users want to confirm with the pre-release of 5.1.0? If you find issues, we'll fix them as part of 5.1.0. Otherwise, we'll look into this more in a future release.

rnicholus avatar Dec 16 '14 17:12 rnicholus

Hi - How can I get a copy of the pre-release of 5.1.0? Thanks.

kngtr avatar Dec 29 '14 23:12 kngtr

We plan to release 5.1.0 this week, so you will be able to give this a spin in the released version.

On Mon, Dec 29, 2014 at 5:57 PM, kngtr [email protected] wrote:

Hi - How can I get a copy of the pre-release of 5.1.0? Thanks.

Reply to this email directly or view it on GitHub: https://github.com/FineUploader/fine-uploader/issues/1158#issuecomment-68316969

rnicholus avatar Dec 30 '14 01:12 rnicholus

@kngtr Have you downloaded 5.1? If so, are you interested in using it to upload directly to Google Cloud Storage?

rnicholus avatar Jan 06 '15 21:01 rnicholus

I would be, do you have a working php sample I could try?

R

On 7 Jan 2015, at 8:09 am, Ray Nicholus [email protected] wrote:

@kngtr Have you downloaded 5.1? If so, are you interested in using it to upload directly to Google Cloud Storage?

— Reply to this email directly or view it on GitHub.

engagingcomms avatar Jan 06 '15 21:01 engagingcomms

We have a number of Fine Uploader S3 PHP samples in the server-examples repo. You'd use Fine Uploader S3 and setup Google Cloud Storage to use S3 compatibility mode. The S3 feature page will provide some additional details, if you need them. Uploading to Cloud Storage with S3 compatibility mode enabled would qualify as an "S3-like" endpoint, which, in theory, should be supported now after changes made in 5.1.

When constructing Fine Uploader S3 client-side, you'd need to specify the Cloud Storage endpoint as request.endpoint and the bucket in objectProperties.bucket.

rnicholus avatar Jan 06 '15 21:01 rnicholus

Thanks rnicholus. I will download and give it a try.

kngtr avatar Jan 07 '15 18:01 kngtr

I'm a google cloud user and I'd love to test this out. I'm a little confused on how to integrate it though using the s3 compatibility mode. Has anyone tried this or explain it a little more in depth?

ghost avatar Jan 19 '15 02:01 ghost

@bryangoldberg What, specifically, are you stuck on? The Google Cloud Storage docs cover a "simple migration" from S3 to Cloud Storage, which allows a CS endpoint to be treated as if it were an S3 bucket.

rnicholus avatar Jan 19 '15 03:01 rnicholus

Has anyone had a chance to test this out with Google Cloud Storage's S3 compatibility mode yet?

rnicholus avatar Feb 11 '15 05:02 rnicholus

Not yet. Hopefully I will let you know next week.

kngtr avatar Feb 11 '15 22:02 kngtr

Ray - I gave a quick try this morning and ran into 'Invalid policy document or request headers!' error. I already replaced AWS-ACCESS-KEY with GOOG-ACCESS-KEY so I will debug more later.

kngtr avatar Feb 12 '15 18:02 kngtr

You'll need to ensure all access keys server side are your cloud storage keys. Also, the credentials.accessKey client-side Fine Uploader S3 option must be set to your GCS access key.

rnicholus avatar Feb 12 '15 18:02 rnicholus

It's far too confusing to set up a google cloud storage upload through the s3. If anyone is trying to, an easy alternative I found is the following (if you are using app engine):

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

$options = [ 'gs_bucket_name' => 'bucket' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload-url', $options);

Then you'll want to store $upload_url into a variable like so:

<script>var upload_link = "<?php echo $upload_url; ?>"</script>

And then continue your fineuploader like normal. Notice the endpoint is the new upload_link variable.

var upload_template = $("#upload_template").fineUploader({
    request: { endpoint: upload_link },
    autoUpload: false, validation: { sizeLimit: 5000000, itemLimit: 1,  allowedExtensions: ['pdf'] },
}).on('complete', function (event, id, name, responseJSON) {

});

Then in your /upload-url have the following to move your new temporary uploaded file:

move_uploaded_file($_FILES['qqfile']['tmp_name'], 'gs://bucket/new_file.pdf');

And boom, you've uploaded a file to your cloud storage to do whatever you want using fine uploader.

ghost avatar Feb 25 '15 22:02 ghost

It looks like you are essentially uploading the file twice (once to your server, then again from your server to the final storage destination), something that Fine Uploader S3 aims to prevent. So, you're not using Fine Uploader S3 at all. Is this correct?

rnicholus avatar Feb 25 '15 22:02 rnicholus

App Engine doesn't allow for writes to the server, only the Cloud Storage, so I "think" it's only uploading it once and then basically renaming the file and making it available in google cloud storage. It's in a hidden temp storage at the time of upload and needs to be moved with move_uploaded_file().

But that is correct, I am currently just using the default Fine Uploader script. I wish I had the time to wrap my head around the Fine Uploader S3, but since I've never used anything CORS or anything in S3 before it's a tad confusing for me.

ghost avatar Feb 25 '15 23:02 ghost

Hmm, ok. I'll admit I'm not very familiar with app engine. Not very = not at all. Thanks for posting this, perhaps it will be useful for others using AE.

I hope to spend some time playing around with GCS after the current in-progress release of Fine Uploader is out the door (5.2).

rnicholus avatar Feb 25 '15 23:02 rnicholus

No problem, that was the goal. Thanks for such a simple and easy uploader tool. It REALLY helped me out. Looking forward to the next release. If you need any help messing with GCS in the future, I'd be happy to try some things out.

ghost avatar Feb 25 '15 23:02 ghost

Shelving this until sometime after 5.3, unless someone reports success using Fine Uploader S3 w/ CDN support in the meantime.

rnicholus avatar Mar 24 '15 21:03 rnicholus

Has anyone tried this lately?

LusciousPear avatar Sep 06 '16 20:09 LusciousPear