Issue getting Firebase Image url using java -maven code [Not android] - java

I have been working on utility where I have written java maven and in which I want to upload the file to the firebase and get the firebase URL for image.
Right Now I am using gsutil: Google cloud storage SDK using below code
Storage storage = StorageOptions.getDefaultInstance()
.getService();
Bucket bucket = storage.get(bucketName);
//... code required
return "gs://" + blobId.getBucket() + "/" + blobId.getName();
But above code is giving me gsutil URL which is not usable in HTML img src.
I want firebase URL which can be used in HTML img tag.
In shor I want download URL using Java-Spring code(not android).

The Firebase Admin SDK provides a fairly thin wrapper around the Google Cloud Storage SDK for Java. In Node.js this is accomplished by calling getSignedUrl(), but it seems on Java that you need getMediaLink() as shown in the Cloud Storage documentation.
Also see:
How to download a file from Google Cloud Storage with Java?

Related

Upload files to Google Drive from App Engine application

I'm trying to implement App Engine app that should upload files from user computer to Team Drive folder.
Currently I'm trying to do it with .jsp and servlets but it seems that it couldn't be done that way.
I'm using Service Account and Drive API Client Library for Java - https://developers.google.com/api-client-library/java/apis/drive/v3
It seems that when uploading files in such way you should use java.io.File which is impossible on App Engine, because file isn't stored on instance but it is uploaded from user computer.
Is it any way to upload file directly to Google Drive using App Engine?
Additional note:
I'm using Drive API v3.
In Drive API v2 there was file.insert() method available which lets you sending InputStream as input parameter. I think such method could help me with upload but it is not included in API v3.
https://developers.google.com/drive/api/v2/reference/files/insert
I think you're looking for protected Create(File content, com.google.api.client.http.AbstractInputStreamContent mediaContent) from https://developers.google.com/resources/api-libraries/documentation/drive/v3/java/latest/

Upload File to Cloud Storage directly using SignedURL

I am trying to upload a file directly to Google Cloud Storage using Java Client Library
The Code I have written is
Instead of uploading the new file to cloud storage I am getting this output
What I am missing in the code to make the upload to Cloud Storage ?
You need configure the the authorization keys, is a file .json to you enverioment,see this in the documentation https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-gcloud
I don't think you have the correct "BUCKET_NAME" set, please compare the bucket name you are using with your bucket name on your Google Cloud Console so you can see if it's set correctly.
The way it's set, it looks like the compiler thought you were using a different constructor for your blobInfo.newBuilder method.

Azure storage blob upload from url

Is there a way to do this?
I have plenty of files over few servers and Amazon s3 storage and need to upload to Azure from an app (Java / Ruby)
I prefer not to download these files on my app server and then upload it to Azure blob storage.
I've checked the Java and Ruby sdk, it seems there's no straight way to do this based on the examples (means I have to download these files first on my app server and upload it to Azure)
Update:
Just found out about CloudBlockBlob.startCopy() in the Java SDK.
Tried it and it's basically what I want without using Third party tools like AzCopy.
You have a few options, mostly licensed, but I think that AzureCopy is your best free alternative. You can check a step by step experience on MSDN Blogs.
All you need is your Access Keys for both services and with a simple command:
azurecopy -i https://mybucket.s3-us-west-2.amazonaws.com/ -o https://mystorage.blob.core.windows.net/mycontainer -azurekey %AzureAccountKey% -s3k %AWSAccessKeyID% -s3sk %AWSSecretAccessKeyID% -blobcopy -destblobtype block
You can pass blobs from one container to the other.
As #EmilyGerner said, AzCopy is the Microsoft offical tool, and AzureCopy that #MatiasQuaranta said is the third party tool on GitHub https://github.com/kpfaulkner/azurecopy.
The simple way is using AWS Command Line and AzCopy to copy all files from S3 to local directory to Azure Blob Storage. You can refer to my answer for the other thread Migrating from Amazon S3 to Azure Storage (Django web app). But it is only suitable for a small data size bucket.
The other effective way is programming with SDKs of Amazon S3 and Azure Blob Storage for Java. Per my experience, Azure SDK APIs for Java is similiar with C#‘s, so you can try to refer to Azure Blob Storage Getstarted doc for Java and AWS SDK for Java to follow #GauravMantri sample code to rewrite code in Java.

Storing an Image/File, passed as Base64 encoded String in request,to GAE datastore

I am creating the server backend of my Android application in Google App Engine/java. there is a functionality of adding a profile picture.
From Android App,i am passing this image as Base64 encoded stream to my App Engine Servlet. I am confused as to how can i store this image(file) using blobstore api .Then i would create IMageURL of this blob using ImageService API.
Can anyone suggest a best way ,on how to ad
Try this:
1) Decode the Base64 string on App Engine. Alternatively, just POST the file itself without encoding it.
2) Store the image on Google Cloud Storage. Here is an example.
3) Retrieve the image from Cloud Storage using the getServingUrl function from the Blobstore API.
If you are doing image manipulations before serving, you can use the Images API.

how can i download a file in google cloud storage using BlobstoreService java

Since 2 days Googling, I got to upload a file in Google Cloud Storage using java. Now I am facing troubles to download the same file from Google Cloud Storage using java.
I tried with BlobstoreService to upload a file. Can any body give me the suggestions to download from the GCS?
If you want to read a file on Google Cloud Storage from an App Engine application, you need to use the Google Cloud Storage Java Client Library, or you can read it using Blobstore API after you get the blobstore key using the function createGsBlobKey.
Using Google Cloud Storage Java Client Library in order to read/write files is fairly simple. Check out this page for more info:
https://developers.google.com/appengine/docs/java/googlecloudstorageclient/getstarted

Categories