使用独立Java应用程序将图像上载到Google App Engine
我正在编写一个简单的、没有UI的、因此没有.jsp/.html文件的、基于控制台的Java应用程序,用于从文件中读取图像文件路径,并将图像上传到Google App Engine上的示例照片提要应用程序 我正在使用ApacheHttpClient对我的应用程序引擎应用程序进行URL连接和POST请求,这是到目前为止我所拥有的代码使用独立Java应用程序将图像上载到Google App Engine,java,google-app-engine,google-apps,google-cloud-datastore,Java,Google App Engine,Google Apps,Google Cloud Datastore,我正在编写一个简单的、没有UI的、因此没有.jsp/.html文件的、基于控制台的Java应用程序,用于从文件中读取图像文件路径,并将图像上传到Google App Engine上的示例照片提要应用程序 我正在使用ApacheHttpClient对我的应用程序引擎应用程序进行URL连接和POST请求,这是到目前为止我所拥有的代码 MultipartEntity multiPartEntity = new MultipartEntity(); multiPartEntity.addPart("ph
MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("photo", new FileBody(new File(filePath)));
multiPartEntity.addPart("title", new StringBody(comment));
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(uploadUrl);
post.setEntity(multiPartEntity);
HttpResponse response = client.execute(post);
这将上载文件,我可以在Blob查看器中看到它。但是,文件的内容类型设置为application/octet-stream
我希望根据图像类型将内容类型设置为image/jpeg或image/png等。我尝试使用
MultipartEntity multiPartEntity = new MultipartEntity();
multiPartEntity.addPart("photo", new FileBody(new File(filePath), "image/jpeg"));
multiPartEntity.addPart("title", new StringBody(comment));
但这甚至未能将文件上传到Blob查看器中,我仍然从应用程序servlet获得相同的响应
有人能帮我破解这个吗