How to convert a File into a StorageObject (Google API) - java

I'm trying to store a file into Google NearLine using a java program and Google's Cloud Storage API. But I'm having difficulty finding out how to do this.
I think I have to convert the File object into a StorageObject, but not sure how to do it.
Here's a link to the doc's for the StorageObject.
https://developers.google.com/resources/api-libraries/documentation/storage/v1beta2/java/latest/com/google/api/services/storage/model/StorageObject.html#set(java.lang.String,%20java.lang.Object)
Thanks.
Note: I've been using this link as a guide:
https://cloud.google.com/storage/docs/json_api/v1/json-api-java-samples
However, this only shows you how to access the bucket, not upload files to the bucket.

To upload files, use Storage.Objects.Insert: https://developers.google.com/resources/api-libraries/documentation/storage/v1beta2/java/latest/com/google/api/services/storage/Storage.Objects.Insert.html

Related

Is it possible to write an image directly to Google Drive?

I have searched Google Drive API reference as well as the Internet for an answer but I haven't found any.
Is it possible to write an image directly to Google Drive from Java app?
I know that you can upload files to Google Drive from local file system via Java app, but that is not what I want.
I have a Java app that is creating an image - BufferedImage object. To save in the local file system, I use javax.imageio.ImageIO.write method and it works well.
However, what I would like to do, is to somehow write that BufferedImage directly to my Google Drive so I don't have to write it to the local file system and then upload it to Google Drive.
Thanks for help :]

How to use Google Cloud storage to upload image file?

These couple day I have been trying to upload images to the Google cloud using Java. However, I did found some source codes around but amazingly, none of them come with the handy lib jar files. I am trying to search for the required jar file but still can not found them all. Here, I am asking, does any one have the sample code that I just directly run? The change of the settings is a necessary but definitely not for libs.
All you need is Java Client for Google Cloud Storage
Howto you will find here: Getting Started

How to specify StorageEncrypted when creating new assets from a transcode in Azure media services

I'm following along with the Using AES-128 Dynamic Encryption and Key Delivery Service tutorial. I am using the Azure java SDK and I can't find a way to use the StorageEncrypted option for newly created assets (i.e. assets created as a result of transcoding). When I upload my high-quality source file I'm able to use setOptions(AssetOption.StorageEncrypted) when creating the Azure asset. I see in the Encode the asset containing the file to the adaptive bitrate MP4 set portion of the tutorial that it is possible to tell Azure I want to use StorageEncrypted on my new asset from the following C# code:
encodeTask.OutputAssets.AddNew(String.Format("{0} as {1}", inputAsset.Name, encodingPreset), AssetCreationOptions.StorageEncrypted);
I found a few vague mentions of encryption in the Task.CreateBatchOperation JavaDocs but it is unclear what they are used for or what values might make sense.
So, my question is: how do I tell Azure to use StorageEncrypted when creating new assets from a transcode using the Java SDK?
I believe I've found the solution in the REST API docs. Basically just add a assetCreationOptions='1' attribute on your outputAsset element in the taskBody.
I'm thinking the Java SDK simply isn't on par with .Net (which makes sense given the source). You might be better off just using the REST API directly as there are several missing pieces in the Java SDK.

How to add Header/Footer in Google Drive from Java API?

I converting HTML file to PDF via Google Drive Service. I want to add Header and Footer on pages. How can do that using Java Google Drive API?
PS: If there is not proper way than any workaround would be appreciated.
I don't think you can do this directly using Google Drive API. If you are fine with some workaround, I would use Google Apps Script FooterSection Class:
Upload file using Files.insert() with option convert=true
Either trigger or keep running script on specific folder which does the following:
Modify Footer using FooterSection Class
Export Google Document file as PDF
In order to export PDF, there are two ways I can think of.
Using Document Class of Apps script
doc.getAs("application/pdf")
Or getting export link of PDF from Google Drive API using Files.list() where you can get downloadable link for PDF.
"exportLinks": {
"application/pdf": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=pdf",
"application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=ods",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=xlsx"
},

Dynamically generating files and providing those files for download in Google App engine

I am creating a web app in google app engine using java which dynamically generate an HTML file. The requirement is such that if the Html file size increases from a certain limit (say 3 mb), then it should be split into two files and zipped together and that zip file should be sent back as the response.
I would like help on how and where to create those temporary HTML files and then zip it, in google app engine as i guess GAE doesnt allow to write on the filesystem.
Please help!!!
You can use the blobstore like a filesystem. Experimentally, they've even added access via the File api!
https://developers.google.com/appengine/docs/java/blobstore/overview#Writing_Files_to_the_Blobstore
You could also use the Google Cloud Storage. The advantage of this one is that once the file is produced, you can easily write scripts to manipulate the files through gsutil.

Categories