저는 App Engine 애플리케이션이 있습니다. Cloud Storage를 사용하여 일부 사용자가 업로드 한 파일을 저장하려고합니다.Google Appengine Cloud Storage
모든 앱 엔진 애플리케이션과 함께 제공되는 단일 무료 버킷에 액세스하는 간단한 인증 방법에 대해 알고 싶습니다.
응용 프로그램 자체 만 클라우드 저장소에 연결하고 사용자는 클라우드 저장소와 상호 작용할 필요가 없습니다. 모든 파일은 동일한 폴더에 배치 할 수 있으며 App Engine JVM에서만 액세스 할 수 있어야합니다.
Oauth2 등을 거치지 않고 인증을위한 간단한 방법이 있습니까? 가능한 경우 간단한 서버 간 액세스!
편집 :이 내용과 동일합니까?
gcloud beta auth application-default login
편집 2 :는 Gcloud에 대한 위의 기본 인증 설정을 시도. 여전히 같은 예외가 발생합니다.
com.google.cloud.storage.StorageException: Invalid Credentials
내가 사용하고
테스트 코드 :
private static Storage storage = null;
static {
storage = StorageOptions.getDefaultInstance().getService();
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
out.println("Hello, world");
testCloudStorage();
}
private void testCloudStorage() throws IOException{
ByteArrayInputStream baIs = new ByteArrayInputStream("TEST FILE CONTENT".getBytes());
uploadFile("test-content.txt", baIs, "xyzabc.appspot.com");
}
/**
* Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
* environment variable, appending a timestamp to end of the uploaded filename.
*/
public String uploadFile(String fileName, InputStream inputStream, final String bucketName) throws IOException {
DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
DateTime dt = DateTime.now(DateTimeZone.UTC);
String dtString = dt.toString(dtf);
final String extendedFileName = fileName + dtString;
// the inputstream is closed by default, so we don't need to close it here
BlobInfo blobInfo =
storage.create(
BlobInfo
.newBuilder(bucketName, extendedFileName)
// Modify access list to allow all users with link to read file
.setAcl(new ArrayList<>(Arrays.asList(Acl.of(Acl.User.ofAllUsers(), Role.READER))))
.build(),
inputStream);
// return the public download link
return blobInfo.getMediaLink();
}
편집 3 :이 내가 다음 단계는 다음과 같습니다
- 나는 기본적인 작업 JSP 샘플 응용 프로그램이 - 모두 devserver 배포 된 버전이 정상적으로 작동 중입니다.
- 데이터 저장소가 작동 중입니다 - 삽입/업데이트/삭제
- 은 내가 GCloud SDK를 설치하고 초기화를하고
공식 문서를 기반으로 시도한 것을 보여주십시오. –
@ZigMandel 이미 애플리케이션 엔진에서 실행중인 JSP 애플리케이션이 있습니다. 클라우드 스토리지를 테스트 할 테스트 서블릿을 만들었습니다. 난 그냥 테스트 파일에 몇 바이트를 작성하고 싶습니다. 질문에 서블릿 코드를 추가했습니다. – Teddy