如何使用 JSON API 和 CloseableHttpClient 将文件上传到 Google Cloud Storage 存储桶?
how to upload a file into Google Cloud Storage bucket using JSON API and CloseableHttpClient?
我正在尝试使用 CloseableHttpClient.getting 响应 200 将 CSV 文件上传到 google 云存储,但内容类型未正确反映。
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response;
try {
ContentBody fileBody = new FileBody(content, ContentType.DEFAULT_BINARY);
HttpEntity entity = MultipartEntityBuilder.create().addPart("FILE_NAME", fileBody)
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE).build();
HttpPost request = new HttpPost(
"https://www.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=media&name=FILE_NAME");
request.addHeader(Constants.API_HEADER_AUTHORIAZATION,
Constants.API_HEADER_AUTHORIAZATION_VALUE + accessToken());
request.setEntity(entity);
response = httpClient.execute(request);
请找到下面上传的Google存储桶截图:
我正在尝试使用 CloseableHttpClient.getting 响应 200 将 CSV 文件上传到 google 云存储,但内容类型未正确反映。
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response;
try {
ContentBody fileBody = new FileBody(content, ContentType.DEFAULT_BINARY);
HttpEntity entity = MultipartEntityBuilder.create().addPart("FILE_NAME", fileBody)
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE).build();
HttpPost request = new HttpPost(
"https://www.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=media&name=FILE_NAME");
request.addHeader(Constants.API_HEADER_AUTHORIAZATION,
Constants.API_HEADER_AUTHORIAZATION_VALUE + accessToken());
request.setEntity(entity);
response = httpClient.execute(request);
请找到下面上传的Google存储桶截图: