2012-03-18 4 views
1

Google Cloud Storage에 앱 엔진 앱의 데이터를 저장하려고합니다.자바 용 gae를 사용하여 Google Cloud Storage에 데이터 저장

만약 내가 로컬 코드가 잘 실행되지만 모든 데이터가 저장되지 않습니다.

앱을 앱에 업로드하면 다음 코드를 실행할 때 널 포인터 예외가 발생합니다. AppEngineFile writableFile = fileService.createNewGSFile (optionsBuilder.build()); dev에 서비스와 Google 스토리지와 파일 서비스를 사용하는 경우

사용하여 전체 코드 메신저

 // Get the file service 
     FileService fileService = FileServiceFactory.getFileService(); 

     /** 
     * Set up properties of your new object 
     * After finalizing objects, they are accessible 
     * through Cloud Storage with the URL: 
     * http://commondatastorage.googleapis.com/my_bucket/my_object 
     */ 
     GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder() 
      .setBucket("blood") 
      .setKey("1234567") 
      .setAcl("public-read") 
      .setMimeType("text/html");//.setUserMetadata("date-created", "092011", "owner", "Jon"); 


     // Create your object 
     AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build()); 

     // Open a channel for writing 
     boolean lockForWrite = true; // Do you want to exclusively lock this object? 
     FileWriteChannel writeChannel = fileService.openWriteChannel(writableFile, lockForWrite); 
     // For this example, we write to the object using the PrintWriter 
     PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8")); 
     out.println("The woods are lovely and deep."); 
     out.println("But I have promises too keep."); 

     // Close the object without finalizing. 
     out.close(); 

     // Finalize the object 
     writeChannel.closeFinally(); 
     System.out.println("Completed writing to google storage"); 

답변

0

그래서 문제는 앱 엔진이 클라우드 저장소에 생성 된 버킷을 읽고 쓸 수있는 권한이 없다는 것입니다.

1

, 그것은 실제로 Google 저장 용량 버킷에 기록하지 않고 로컬 파일 시스템에 - 당신이 기대된다 그것은 Google 스토리지에 쓸 수 있습니까?

null 포인터 예외에 대해 스택 추적을보고 잘못되었는지 확인해야합니다.

+1

당신은 BlobStore의 "내장"서비스에 대해 이야기하고 있습니다. Google Cloud Storage는 개발 환경과 운영 환경 (appspot.com) 모두에 대한 외부 서비스입니다. – alex

+0

Right Alex는 완벽하게 이해합니다. 문제에 대한 어떤 생각? – Vik

+2

앱 엔진 개발 서버에서 파일 API를 사용하면 외부 Google 스토리지 서비스를 읽거나 쓰지 않지만 로컬 디스크 읽기 및 쓰기를 모방한다고합니다. –

관련 문제