0

I am trying to upload video file from android emulator to server but its giving me following exception:

2020-06-08 11:33:22.362 9817-9817/com.example.app E/CreateActivity: New Post Error: /document/primary:Movies/VID-20200526-WA0006.mp4: open failed: ENOENT (No such file or directory)
java.io.FileNotFoundException: /document/primary:Movies/VID-20200526-WA0006.mp4: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:492)
    at java.io.FileInputStream.<init>(FileInputStream.java:159)
    at okio.Okio.source(Okio.java:168)

Here is mt code stuff:

fun prepareFilePart(partName: String, uri: Uri, context: Context): MultipartBody.Part {
    val file = File(uri.path)
    val requestFile: RequestBody = RequestBody.create(
            MediaType.parse(context.contentResolver.getType(uri)),
            file)
    return  MultipartBody.Part.createFormData(partName, file.name, requestFile)
}

its not able to create file itself. I am working android 29

Sandeep Tiwari
  • 2,042
  • 3
  • 24
  • 47
  • A `Uri` is not a `File`, and you should not need a `File` for uploading a video identified by a `Uri`. – CommonsWare Jun 08 '20 at 10:58
  • @CommonsWare kindly provide example OR code snippet, I followed given link, its not working for me – Sandeep Tiwari Jun 08 '20 at 11:57
  • "its not working for me" -- then perhaps ask a separate Stack Overflow question with a [mcve] showing what you tried and explaining in detail what problems you are encountering. – CommonsWare Jun 08 '20 at 12:14
  • @CommonsWare I have posted another question could you please help me out https://stackoverflow.com/questions/62275348/issue-to-upload-video-file-from-android-device-to-springboot-rest-api – Sandeep Tiwari Jun 09 '20 at 05:02

0 Answers0