use of com.google.appengine.tools.cloudstorage.GcsFileOptions.Builder in project pratilipi by Pratilipi.
the class BlobAccessorGcsImpl method createOrUpdateBlob.
@Override
public BlobEntry createOrUpdateBlob(BlobEntry blobEntry) throws UnexpectedServerException {
GcsFilename gcsFileName = new GcsFilename(bucketName, blobEntry.getName());
Builder builder = new GcsFileOptions.Builder();
if (blobEntry.getMimeType() != null)
builder.mimeType(blobEntry.getMimeType());
if (blobEntry.getCacheControl() != null)
builder.cacheControl(blobEntry.getCacheControl());
if (blobEntry.getMetaName() != null)
builder.addUserMetadata(BlobEntry.META_NAME, blobEntry.getMetaName());
GcsFileOptions gcsFileOptions = builder.build();
try {
GcsOutputChannel gcsOutputChannel = gcsService.createOrReplace(gcsFileName, gcsFileOptions);
gcsOutputChannel.write(ByteBuffer.wrap(blobEntry.getData()));
gcsOutputChannel.close();
} catch (IOException ex) {
logger.log(Level.INFO, "Failed to create/update blob with name '" + blobEntry.getName() + "'", ex);
throw new UnexpectedServerException();
}
return null;
}
use of com.google.appengine.tools.cloudstorage.GcsFileOptions.Builder in project activityinfo by bedatadriven.
the class GcsBlobFieldStorageService method put.
public void put(AuthenticatedUser user, String contentDisposition, String mimeType, BlobId blobId, ResourceId formId, InputStream inputStream) throws IOException {
ResourceId userId = CuidAdapter.userId(user.getUserId());
assertNotAnonymousUser(user);
if (!hasAccessToResource(userId, formId)) {
throw new WebApplicationException(UNAUTHORIZED);
}
GcsFileOptions gcsFileOptions = new Builder().contentDisposition(contentDisposition).mimeType(mimeType).addUserMetadata(GcsUploadCredentialBuilder.X_CREATOR, userId.asString()).addUserMetadata(GcsUploadCredentialBuilder.X_OWNER, formId.asString()).build();
GcsOutputChannel channel = GcsServiceFactory.createGcsService().createOrReplace(new GcsFilename(bucketName, blobId.asString()), gcsFileOptions);
try (OutputStream outputStream = Channels.newOutputStream(channel)) {
IOUtils.copy(inputStream, outputStream);
}
}
use of com.google.appengine.tools.cloudstorage.GcsFileOptions.Builder in project activityinfo by bedatadriven.
the class SubmissionArchiver method backup.
public void backup(ResourceId formClassId, ResourceId formId, ByteSource byteSource) {
try {
DateTime submissionTime = new DateTime(DateTimeZone.UTC);
String path = Joiner.on('/').join(formClassId, dateFormat.print(submissionTime), timeFormat.print(submissionTime) + " " + formId + ".xml");
GcsFilename gcsFilename = new GcsFilename(bucketName, path);
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
GcsFileOptions gcsFileOptions = new Builder().mimeType(MediaType.MULTIPART_FORM_DATA).build();
GcsOutputChannel channel = gcsService.createOrReplace(gcsFilename, gcsFileOptions);
try (OutputStream outputStream = Channels.newOutputStream(channel)) {
byteSource.copyTo(outputStream);
}
LOGGER.log(Level.INFO, "Archived XForm to " + gcsFilename);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Form submission could not be backed up to GCS", e);
try {
LOGGER.info(byteSource.asCharSource(Charsets.UTF_8).read());
} catch (IOException ioException) {
}
}
}
Aggregations