Data Upload in Google Drive
Hi all,
I am searching for ways to upload data from AEM author instance to google drive. Is there any documentation which would be help me in this.
Thanks in advance.
Hi all,
I am searching for ways to upload data from AEM author instance to google drive. Is there any documentation which would be help me in this.
Thanks in advance.
Approach I:
Create the scripts/scheduler/workflow for the asset to be pushed from AEM to google drive.
There are google drive APIs available for pushing the data to google drive.
https://developers.google.com/drive/api/guides/manage-uploads
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
/* Class to demonstrate use of Drive insert file API */
public class UploadBasic {
/**
* Upload new file.
* @return Inserted file metadata if successful, {@code null} otherwise.
* @throws IOException if service account credentials file not found.
*/
public static String uploadBasic() throws IOException{
// Load pre-authorized user credentials from the environment.
// TODO(developer) - See https://developers.google.com/identity for
// guides on implementing OAuth2 for your application.
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
credentials);
// Build a new authorized API client service.
Drive service = new Drive.Builder(new NetHttpTransport(),
GsonFactory.getDefaultInstance(),
requestInitializer)
.setApplicationName("Drive samples")
.build();
// Upload file photo.jpg on drive.
File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
// File's content.
java.io.File filePath = new java.io.File("files/photo.jpg");
// Specify media type and file-path for file.
FileContent mediaContent = new FileContent("image/jpeg", filePath);
try {
File file = service.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
return file.getId();
}catch (GoogleJsonResponseException e) {
// TODO(developer) - handle error appropriately
System.err.println("Unable to upload file: " + e.getDetails());
throw e;
}
}
}You can use this to upload to google drive and for getting the metadata or the file object from the AEM server and get the input stream from it and convert it to a file object, that you can refer in the above java code
Asset asset = assetResource.adaptTo(Asset.class);
Rendition original = asset.getOriginal();
if (original != null) {
InputStream stream = original.getStream();
// add your logic
}
Approach II: Based on the events, create a connection with AEM + Adobe IO and get all the event captured at Adobe IO journal. Then read the Adobe IO journal in your Firefly app that you can create using the Node.JS and from there create the scheduler that will run and get the data from AEM and do the processing over here.
Advantage of Approach II : The AEM server will not be overloaded with all the processing operations required for moving the images/asset from AEM to Google Drive.
Disadvantages : Need to maintain a separate codebase for the firefly app and need to be aware of Node.js.
Hope this helps!
Thanks
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.