本文整理汇总了Java中com.google.appengine.api.blobstore.BlobstoreService.createGsBlobKey方法的典型用法代码示例。如果您正苦于以下问题:Java BlobstoreService.createGsBlobKey方法的具体用法?Java BlobstoreService.createGsBlobKey怎么用?Java BlobstoreService.createGsBlobKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.blobstore.BlobstoreService
的用法示例。
在下文中一共展示了BlobstoreService.createGsBlobKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serveFileFromCloudStorage
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
public static void serveFileFromCloudStorage(String bucketName,
String objectName,
String contentType,
HttpServletResponse resp) throws IOException {
// GcsFilename fileName = getFileName(req);
GcsFilename fileName = new GcsFilename(bucketName, objectName);
// resp.setContentType("video/webm");
resp.setContentType(contentType);
if (SERVE_USING_BLOBSTORE_API) {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
"/gs/" + fileName.getBucketName() + "/" + fileName.getObjectName());
blobstoreService.serve(blobKey, resp);
} else {
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
copy(Channels.newInputStream(readChannel), resp.getOutputStream());
}
}
示例2: loadSchema
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
private void loadSchema(String fileUri, TableSchema schema) throws IOException {
// TODO(frew): Move to AnalysisUtility
String schemaFileUri = fileUri + ".schema";
String schemaFileName = "/gs/" + schemaFileUri.substring(schemaFileUri.indexOf("//") + 2);
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey key = blobstoreService.createGsBlobKey(schemaFileName);
System.out.println("Schema File Name : " + schemaFileName);
String schemaLine = AnalysisUtility.loadSchemaStr(schemaFileName);
String[] schemaFieldStrs = schemaLine.split(",");
List<TableFieldSchema> schemaFields = new ArrayList<TableFieldSchema>(schemaFieldStrs.length);
for (String schemaFieldStr : schemaFieldStrs) {
TableFieldSchema field = new TableFieldSchema();
String[] schemaFieldStrParts = schemaFieldStr.split(":");
field.setName(schemaFieldStrParts[0]);
field.setType(schemaFieldStrParts[1]);
field.setMode("NULLABLE");
schemaFields.add(field);
}
schema.setFields(schemaFields);
}
示例3: testCreateGsBlobKey
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
@Test
@InSequence(100)
public void testCreateGsBlobKey() throws Exception {
final long ts = System.currentTimeMillis();
final byte[] bytes = "FooBar".getBytes();
GcsService service = GcsServiceFactory.createGcsService();
GcsFilename filename = new GcsFilename("GcsBucket", String.valueOf(ts));
GcsFileOptions options = new GcsFileOptions.Builder().mimeType(CONTENT_TYPE).build();
try (GcsOutputChannel out = service.createOrReplace(filename, options)) {
IOUtils.copy(Channels.newChannel(new ByteArrayInputStream(bytes)), out);
}
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey key = blobstoreService.createGsBlobKey("/gs/GcsBucket/" + ts);
byte[] fetched = blobstoreService.fetchData(key, 0, 10);
Assert.assertArrayEquals(bytes, fetched);
}
示例4: doGet
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
/**
* Retrieves a file from GCS and returns it in the http response.
* If the request path is /gcs/Foo/Bar this will be interpreted as
* a request to read the GCS file named Bar in the bucket Foo.
*/
//[START doGet]
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
GcsFilename fileName = getFileName(req);
if (SERVE_USING_BLOBSTORE_API) {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
"/gs/" + fileName.getBucketName() + "/" + fileName.getObjectName());
blobstoreService.serve(blobKey, resp);
} else {
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
copy(Channels.newInputStream(readChannel), resp.getOutputStream());
}
}
示例5: testGetMetadataAfterBlobstoreUpload
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
@Test
public void testGetMetadataAfterBlobstoreUpload() throws IOException {
Date expectedDate = new Date(12345678L);
String expectedFilename = "my-file";
long expectedSize = 123456789L;
String expectedMd5Hash = "abcdefghijklmnop";
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
GcsFilename expectedGcsFilename = new GcsFilename("my-bucket", expectedFilename);
BlobKey expectedKey = blobstoreService.createGsBlobKey(
getPathForGcsFilename(expectedGcsFilename));
BlobStorageFactory
.getBlobInfoStorage()
.saveBlobInfo(
new BlobInfo(
expectedKey,
"text",
expectedDate,
expectedFilename,
expectedSize,
expectedMd5Hash));
GcsFileMetadata metadata = rawGcsService.getObjectMetadata(expectedGcsFilename, 0);
assertEquals("", metadata.getEtag());
assertEquals(expectedGcsFilename, metadata.getFilename());
assertEquals(expectedDate, metadata.getLastModified());
assertEquals(GcsFileOptions.getDefaultInstance(), metadata.getOptions());
assertEquals(expectedSize, metadata.getLength());
assertEquals(Collections.emptyMap(), metadata.getXGoogHeaders());
}
示例6: doGet
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//[START original_image]
// Read the image.jpg resource into a ByteBuffer.
FileInputStream fileInputStream = new FileInputStream(new File("WEB-INF/image.jpg"));
FileChannel fileChannel = fileInputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int)fileChannel.size());
fileChannel.read(byteBuffer);
byte[] imageBytes = byteBuffer.array();
// Write the original image to Cloud Storage
gcsService.createOrReplace(
new GcsFilename(bucket, "image.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(imageBytes));
//[END original_image]
//[START resize]
// Get an instance of the imagesService we can use to transform images.
ImagesService imagesService = ImagesServiceFactory.getImagesService();
// Make an image directly from a byte array, and transform it.
Image image = ImagesServiceFactory.makeImage(imageBytes);
Transform resize = ImagesServiceFactory.makeResize(100, 50);
Image resizedImage = imagesService.applyTransform(resize, image);
// Write the transformed image back to a Cloud Storage object.
gcsService.createOrReplace(
new GcsFilename(bucket, "resizedImage.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(resizedImage.getImageData()));
//[END resize]
//[START rotate]
// Make an image from a Cloud Storage object, and transform it.
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/" + bucket + "/image.jpeg");
Image blobImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform rotate = ImagesServiceFactory.makeRotate(90);
Image rotatedImage = imagesService.applyTransform(rotate, blobImage);
// Write the transformed image back to a Cloud Storage object.
gcsService.createOrReplace(
new GcsFilename(bucket, "rotatedImage.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(rotatedImage.getImageData()));
//[END rotate]
// Output some simple HTML to display the images we wrote to Cloud Storage
// in the browser.
PrintWriter out = resp.getWriter();
out.println("<html><body>\n");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/image.jpeg' alt='AppEngine logo' />");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/resizedImage.jpeg' alt='AppEngine logo resized' />");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/rotatedImage.jpeg' alt='AppEngine logo rotated' />");
out.println("</body></html>\n");
}
示例7: doGet
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//[START original_image]
// Read the image.jpg resource into a ByteBuffer.
FileInputStream fileInputStream = new FileInputStream(new File("WEB-INF/image.jpg"));
FileChannel fileChannel = fileInputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int) fileChannel.size());
fileChannel.read(byteBuffer);
byte[] imageBytes = byteBuffer.array();
// Write the original image to Cloud Storage
gcsService.createOrReplace(
new GcsFilename(bucket, "image.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(imageBytes));
//[END original_image]
//[START resize]
// Get an instance of the imagesService we can use to transform images.
ImagesService imagesService = ImagesServiceFactory.getImagesService();
// Make an image directly from a byte array, and transform it.
Image image = ImagesServiceFactory.makeImage(imageBytes);
Transform resize = ImagesServiceFactory.makeResize(100, 50);
Image resizedImage = imagesService.applyTransform(resize, image);
// Write the transformed image back to a Cloud Storage object.
gcsService.createOrReplace(
new GcsFilename(bucket, "resizedImage.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(resizedImage.getImageData()));
//[END resize]
//[START rotate]
// Make an image from a Cloud Storage object, and transform it.
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/" + bucket + "/image.jpeg");
Image blobImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform rotate = ImagesServiceFactory.makeRotate(90);
Image rotatedImage = imagesService.applyTransform(rotate, blobImage);
// Write the transformed image back to a Cloud Storage object.
gcsService.createOrReplace(
new GcsFilename(bucket, "rotatedImage.jpeg"),
new GcsFileOptions.Builder().mimeType("image/jpeg").build(),
ByteBuffer.wrap(rotatedImage.getImageData()));
//[END rotate]
// [START servingUrl]
// Create a fixed dedicated URL that points to the GCS hosted file
ServingUrlOptions options = ServingUrlOptions.Builder
.withGoogleStorageFileName("/gs/" + bucket + "/image.jpeg")
.imageSize(150)
.crop(true)
.secureUrl(true);
String url = imagesService.getServingUrl(options);
// [END servingUrl]
// Output some simple HTML to display the images we wrote to Cloud Storage
// in the browser.
PrintWriter out = resp.getWriter();
out.println("<html><body>\n");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/image.jpeg' alt='AppEngine logo' />");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/resizedImage.jpeg' alt='AppEngine logo resized' />");
out.println("<img src='//storage.cloud.google.com/" + bucket
+ "/rotatedImage.jpeg' alt='AppEngine logo rotated' />");
out.println("<img src='" + url + "' alt='Hosted logo' />");
out.println("</body></html>\n");
}
示例8: serveFileFromGCS
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
/**
* Serves an existing file from the Google Cloud Storage. This method uses
* If-Modified-Since and similar HTTP headers and sends 304 if the file was
* not changed.
*
* @param gcsService GCS
* @param md GCS file meta data
* @param request HTTP request
* @param resp HTTP response
* @param contentType MIME type of the response
* @throws IOException error reading or sending the file
*/
public static void serveFileFromGCS(GcsService gcsService,
GcsFileMetadata md,
HttpServletRequest request, HttpServletResponse resp,
String contentType) throws IOException {
SimpleDateFormat httpDateFormat =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
String ims = request.getHeader("If-Modified-Since");
boolean serve = true;
if (ims != null) {
Date lastSeen;
try {
lastSeen = httpDateFormat.parse(ims);
if (lastSeen.getTime() >= md.getLastModified().getTime()) {
serve = false;
}
} catch (ParseException e) {
// ignore
}
} else {
String inm = request.getHeader("If-None-Match");
if (inm != null) {
String[] split = inm.split(",");
if (Arrays.asList(split).contains(md.getEtag())) {
serve = false;
}
}
}
resp.setContentType(contentType);
resp.setHeader("ETag", md.getEtag());
resp.setHeader("Last-Modified",
httpDateFormat.format(md.getLastModified()));
BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
GcsFilename f = md.getFilename();
BlobKey blobKey =
blobstoreService.createGsBlobKey("/gs/" + f.getBucketName() +
"/" + f.getObjectName());
if (serve) {
blobstoreService.serve(blobKey, resp);
} else {
resp.sendError(304);
}
}
示例9: getImageFromGcs
import com.google.appengine.api.blobstore.BlobstoreService; //导入方法依赖的package包/类
/**
* Retrieves the Image from Google Cloud Storage.
*
* @param bucketName the bucket name of the Google Cloud Storage.
* @param objectName the object path to the image in the Google Cloud Storage.
* @return
*/
private Image getImageFromGcs(String bucketName, String objectName) {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
"/gs/" + bucketName + "/" + objectName);
return ImagesServiceFactory.makeImageFromBlob(blobKey);
}