简体   繁体   English

如何将带有其他数据的图像上传到谷歌驱动器应用程序特定文件夹中,并在 Swift 中以 json 格式返回应用程序

[英]How to upload image with other data into the google drive app specific folder and get back into the app in json formate in Swift

I have successfully integration the google drive sync by using this link has the source code And now I am not able to upload image with its name id and location, I want to upload image with some other fields like name, height, width into the app specific private folder, If this is not possible can any one suggest me how to go with this: Actually I have to sync application list data in which list contains images, title, comments ratings and so forth.我已经通过使用此链接成功集成了谷歌驱动器同步有源代码现在我无法上传带有名称 ID 和位置的图像,我想将带有其他字段(如名称、高度、宽度)的图像上传到应用程序中特定的私人文件夹,如果这是不可能的,任何人都可以建议我如何处理这个:实际上我必须同步应用程序列表数据,其中列表包含图像、标题、评论评级等。 I am able to upload all other fields except images in json formate, any suggestion upload some type of approach to get this我可以上传除 json 格式的图像之外的所有其他字段,任何建议上传某种类型的方法来获取此信息

Found the solution找到解决方案

It is not proper solution but till I am not getting the exact solution, perfect for me.这不是正确的解决方案,但直到我没有得到确切的解决方案,这对我来说是完美的。

To upload image with other request data, I have followed following steps:要上传带有其他请求数据的图像,我遵循了以下步骤:

  1. Convert the image into data using one of the following way使用以下方式之一将图像转换为数据

Swift 4斯威夫特 4

let dataObj = image.pngData()

Swift 3斯威夫特 3

let dataObj = UIImagePNGRepresentation(image)
  1. And convert this data objet to string with utf8并使用 utf8 将此数据对象转换为字符串

    let str = String(decoding: data, as: UTF8.self)

Use this string to upload with other requst param or data.使用此字符串与其他请求参数或数据一起上传。

And don't forgot to mention the type with this, so that you can easily convert this string to data again and from data, image easily can convert.并且不要忘记提及类型,以便您可以轻松地将此字符串再次转换为数据,并且可以轻松地将数据、图像转换为数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM