현재 Google Cloud Storage에 파일을 업로드 할 수있는 프로젝트를 진행 중입니다. 그래서 우리는 버킷을 생성하고 난 내 로컬 "정상"응용 프로그램에 메이븐 의존성을 추가 : Google Cloud Storage에 이미지 저장
<dependencies>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
가 그럼 난 로컬 파일을 읽기 시작하고, 단지 주에 구글 클라우드 스토리지에 저를 밀어 시도 :
try {
final GcsService gcsService = GcsServiceFactory
.createGcsService();
File file = new File("/tmp/test.jpg");
FileInputStream fis = new FileInputStream(file);
GcsFilename fileName = new GcsFilename("test1213","test.jpg");
GcsOutputChannel outputChannel;
outputChannel = gcsService.createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
copy(fis, Channels.newOutputStream(outputChannel));
} catch (IOException e) {
e.printStackTrace();
}
내 copy
방법은 다음과 같습니다
private static final int BUFFER_SIZE = 2 * 1024 * 1024;
private static void copy(InputStream input, OutputStream output)
throws IOException {
try {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = input.read(buffer);
while (bytesRead != -1) {
output.write(buffer, 0, bytesRead);
bytesRead = input.read(buffer);
}
} finally {
input.close();
output.close();
}
}
나는 그에게서 얻는 모든이입니다 The API package 'channel' or call 'CreateChannel()' was not found
그것은 이러한 AppEngine에 앱없이 appengine.tools -> gcs-client
를 사용 할 수있는 방법이 없다는 것을 말한다 :
The API package 'file' or call 'Create()' was not found.
도 빙에서 검색, 구글에서 많이 검색 문서화를 읽은 후 나는이 항목을 발견했다. 그러나 App Engine 서비스를 사용하지 않고도 Google Cloud Storage에 파일을 업로드하는 쉬운 방법이 있습니까?
감사를 바랍니다. 이 json-api로 시도하고 놀고 난 후에 나는 되돌아 올 것이다! +1에 대한 빠른 도움말 : – DominikAngerer