1
JSP를 통해 내 GCS로 파일을 업로드 할 수 없습니다.봄 MVC를 사용하여 Google 클라우드 저장소에 대한 멀티 파트 요청을 통해 파일 업로드
<form enctype="multipart/form-data" action="/gcs/uploud/" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
컨트롤러 :
이 HTML을 사용하여
@Controller
@RequestMapping("pages/gcs/*")
public class GoogleStorageController {
public static final boolean SERVE_USING_BLOBSTORE_API = false;
private final GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
.initialRetryDelayMillis(10)
.retryMaxAttempts(10)
.totalRetryPeriodMillis(15000)
.build());
private static final int BUFFER_SIZE = 2 * 1024 * 1024;
private static String BucketName = "XXXXXX";
@RequestMapping(value ="*/*",method = RequestMethod.POST)
public @ResponseBody String home(HttpServletRequest req, HttpServletResponse resp) {
GcsFileOptions instance = GcsFileOptions.getDefaultInstance();
GcsFilename fileName = getFileName(req);
GcsOutputChannel outputChannel;
try {
outputChannel = gcsService.createOrReplace(fileName, instance);
copy(req.getInputStream(), Channels.newOutputStream(outputChannel));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "successPage";
}
private GcsFilename getFileName(HttpServletRequest req) {
return new GcsFilename(BucketName, "media");
}
/**
* Transfer the data from the inputStream to the outputStream. Then close both streams.
*/
private 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();
}
}
}
내가 내 GCS 파일을 얻었으나, 헤더는 올바르지 않습니다.
의견이 있으십니까? HTTP 헤더 요청을 어떻게 처리해야합니까? 콘텐츠 형식 필드는 어떻게 정의해야합니까?