gpt4 book ai didi

android - 如何在服务器上传多个图像文件?

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:19 24 4
gpt4 key购买 nike

我正在尝试使用 asynctask httpclient 在服务器中上传多个图像。我知道如何上传单张图片,但我不知道如何上传多张图片。我试着...

for (int i = 0; i < photo.length; i++) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo[photoIndex].compress(Bitmap.CompressFormat.PNG, 100, stream);
InputStream in = new ByteArrayInputStream(stream.toByteArray());
params.put("uploaded_file[" + photo[i] + "]", in,
System.currentTimeMillis() + ".jpg");
}

现在我想发送文件路径如何将我的文件路径发送到 PHP 服务器。

在这段代码中,我对多张图片使用了位图数组 photo[photoIndex]。通过这段代码,我可以将我的多张照片的位图发送到 PHP 服务器。

这是上传单张照片的代码。

ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo[photoIndex].compress(Bitmap.CompressFormat.PNG, 100, stream);
InputStream in = new ByteArrayInputStream(stream.toByteArray());
params.put("uploaded_file", in,
System.currentTimeMillis() + ".jpg");

这是正常运行的。

最佳答案

for (String p : YOURARRAYLIST) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo[photoIndex].compress(Bitmap.CompressFormat.PNG, 100, stream);
InputStream in = new ByteArrayInputStream(stream.toByteArray());
params.put("uploaded_file", in,
System.currentTimeMillis() + ".jpg");
}

关于android - 如何在服务器上传多个图像文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30136140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com