开发者

How to upload image to graphql server in android studio?

I am new to graphql and I am trying to upload an image to the graphql server and I don't know how to start. I am using the images from the gallery. The document says to convert the file into an Upload scalar as such

If you're on Android/JVM,开发者_开发知识库 you can turn a File into an upload

val upload = File.toUpload("application/json")

On multiplatform, you can use DefaultUpload

val upload = DefaultUpload.Builder()
              .fileName("filename.txt")
              .content { sink ->
                okioSource.use { sink.writeAll(it) }
              }
              .build()

I tried creating the file from the uri as such

val file = uri.toFile() 

and creating the upload variable as

val upload = file.toUpload("application/json")

But it is giving me "open failed: ENOENT (No such file or directory)" error I couldn't find related documents or examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜