简体   繁体   中英

How should I upload text with images Swift

I am tryin got upload a document/textView with images to my server...

Now I am trying to figure out what would be the best way:

1) You can add the images 1 by 1 to UITextView and lower the quality and upload the whole textView NSAtributedString as a NSData file or a .txt file, and then decode it when downloading.

2) While adding the images to the UITextView I upload them to the server and store a URL link to the images in the UITextView in the same place of the image, and before upload the text with the url's I convert that all to HTML and then display that in a UIWebView.

Now first option seems to be the easiest to setup, but not neccessarily the quickiest, as the final file you upload could be 2-10 mb with roughly 5-7 images with a basic quality....

Now the second option is done in app's like WordPress, and looking at they're code on github Github WordPress Keyboard they convert it differently to html using " libxml2 " and store the url for the image when adding it.... And this option seems to be alot quicker I would of thought...

Now I think the second option would be the best, but I am pretty sure it can be done without using the amount of code wordpress use.

Is there a way of changing the url of an image when adding it as NSTextAttachment? Because when you convert NSAttributedText to html, the image just gets the local link to the file, and the name of the file is just "attachment"..

Now If anyone could give me some advice or better options that would be great!

Many thanks to anyone that spares some time to read this!

Create an image upload service which accept image and url as argument. Then you can generate those image url before sending them to image server and replace those local url with the generated image url.

Edit:

Maybe you can store the location of those images and remove them from the NSattributedstring first and replace with <img src = "url"> before converting it to "HTML".
But I would suggest you using one of those HTML Parser such as KANNA .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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