如何将图像 url 作为多部分发送到服务器?

时间:2021-01-07 13:56:33

标签: android retrofit uri multipart

我从后端获取图像 URL 作为字符串 URL,现在我需要再次将其发送到服务器,在将其转换为 multipart 和 Uri 时出现错误

            File file = null;
            file = new File(Environment.getExternalStorageDirectory() + File.separator + "Photo1");
            file.createNewFile();


            InputStream image_stream = getContentResolver().openInputStream(myUri1);
            Bitmap bitmap= BitmapFactory.decodeStream(image_stream );



            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100 , bos); // YOU can also save it in JPEG
            byte[] bitmapdata = bos.toByteArray();

            FileOutputStream fos = new FileOutputStream(file);
            fos.write(bitmapdata);
            fos.flush();
            fos.close();

            RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
            parts1 =MultipartBody.Part.createFormData("Photo1", file.getName(), requestBody);
            Log.d("@@parts1", String.valueOf(parts1));

        } catch (IOException e) {
            e.printStackTrace();
            Log.d("@@IOException", e.getMessage());
        }

我收到一个错误

D/@@IOException: No content provider: http://anothercz.yilstaging.com/writable/uploads/20210107/1610027045_73aae04fa7f668e42a12.png

请帮助我如何解决它,我会感谢每一个答案

0 个答案:

没有答案
相关问题