在android中设置图像类型

发布于 2024-10-16 19:00:39 字数 1133 浏览 2 评论 0原文

我有一些代码将图像发布到上传到数据库的 php 脚本,当它添加到数据库时,文件类型是 application/oct??? (这是什么)

有没有办法在android阶段将其更改为jpg文件?

下面是我的代码

HttpClient client = new DefaultHttpClient();  
             String postURL = "http://10.0.2.2:90/mobileupload3.php";                
             HttpPost post = new HttpPost(postURL); 


         FileBody bin = new FileBody(file);

         MultipartEntity reqEntity = new MultipartEntity();  
         reqEntity.addPart("image", bin);
         reqEntity.addPart("name", new StringBody(enteredName));
         reqEntity.addPart("gender", new StringBody(radio));
         reqEntity.addPart("cat", new StringBody(radio2));
         reqEntity.addPart("lat", new StringBody(lat));
         reqEntity.addPart("lon", new StringBody(lon));

         post.setEntity(reqEntity);  
         HttpResponse response = client.execute(post);  
         HttpEntity resEntity = response.getEntity();  
         if (resEntity != null) {    
                   Log.i("RESPONSE",EntityUtils.toString(resEntity));
             }
    } catch (Exception e) {
        e.printStackTrace();
    }

    }
}

I have some code to post an image to my php script that uploads to a database, when it adds to the database the file type is application/oct???? (what is this)

is there anyway of changing this to a jpg file at the android stage?

Below is my code

HttpClient client = new DefaultHttpClient();  
             String postURL = "http://10.0.2.2:90/mobileupload3.php";                
             HttpPost post = new HttpPost(postURL); 


         FileBody bin = new FileBody(file);

         MultipartEntity reqEntity = new MultipartEntity();  
         reqEntity.addPart("image", bin);
         reqEntity.addPart("name", new StringBody(enteredName));
         reqEntity.addPart("gender", new StringBody(radio));
         reqEntity.addPart("cat", new StringBody(radio2));
         reqEntity.addPart("lat", new StringBody(lat));
         reqEntity.addPart("lon", new StringBody(lon));

         post.setEntity(reqEntity);  
         HttpResponse response = client.execute(post);  
         HttpEntity resEntity = response.getEntity();  
         if (resEntity != null) {    
                   Log.i("RESPONSE",EntityUtils.toString(resEntity));
             }
    } catch (Exception e) {
        e.printStackTrace();
    }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2024-10-23 19:00:39

application/oct (我假设你的意思是 application/octet-stream)是一个 MIME 类型为一般的二进制文件。

如果没有有关上传方法的更多信息,我相信您问题的其他部分已经在 SO 此处

application/oct (I assume you mean application/octet-stream) is a MIME type for a general binary file.

Without more information on your method of upload, I believe that the other part of your question has already been answered on SO here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文