로컬 Google 앱 엔진 개발 서버에서 gcs 클라이언트 라이브러리 + java를 사용하여 이미지 파일을 업로드하려고합니다. 이미지가 성공적으로 업로드되고 localhost : 8888 / _ah / admin / datastore 아래의 로컬 데이터 저장소에 생성 된 항목을 볼 수 있습니다.
내 애플리케이션에 이미지를 표시 할 수 있도록 업로드 된 이미지의 공개 키를 얻는 방법. 예제 프로필 그림.
코드의 샘플 사본 :
String filePath = Constants.gcsUrl + "/" + bucketName + "/"+ objectName;
GcsService gcsService = GcsServiceFactory
.createGcsService(new RetryParams.Builder()
.initialRetryDelayMillis(10).retryMaxAttempts(10)
.totalRetryPeriodMillis(15000).build());
GcsFilename filename = new GcsFilename(bucketName, objectName);
GcsFileOptions options = new GcsFileOptions.Builder()
.addUserMetadata("cache-control",
"max-age=" + (86400 * 365)).mimeType(mimeType)
.acl(ACL_PUBLIC_READ).build();
GcsOutputChannel writeChannel = gcsService.createOrReplace(
filename, options);
writeChannel.write(ByteBuffer.wrap(fileBytes));
writeChannel.close();
로컬 devserver에서 이미지 서비스를 사용할 수 있습니다. 이를 위해서는 blobkey가 필요합니다.
BlobstoreService blobStore = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobStore.createGsBlobKey("/gs/" + filename.getBucketName() + "/" + filename.getObjectName())); // blobKey can be persisted
ImagesService imagesService = ImagesServiceFactory.getImagesService();
String url = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(image));
크기 조정은을 추가하여 로컬 devserver에서도 작동 =sxxxx
하지만 네이티브 이미지 크기를 가져올 수는 없습니다. 프로덕션시 =s0
URL에 추가 하면 원본 이미지를 가져 오지만 로컬에서 작동하지 않습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다