Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用独立Java应用程序将图像上载到Google App Engine_Java_Google App Engine_Google Apps_Google Cloud Datastore - Fatal编程技术网

使用独立Java应用程序将图像上载到Google App Engine

使用独立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

我正在编写一个简单的、没有UI的、因此没有.jsp/.html文件的、基于控制台的Java应用程序,用于从文件中读取图像文件路径,并将图像上传到Google App Engine上的示例照片提要应用程序

我正在使用ApacheHttpClient对我的应用程序引擎应用程序进行URL连接和POST请求,这是到目前为止我所拥有的代码

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获得相同的响应

有人能帮我破解这个吗