无需编码即可将NSData转换为NSString [英] Converting NSData to NSString without encoding

查看:294
本文介绍了无需编码即可将NSData转换为NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像上传到服务器的数据库。

I am trying to upload a image onto server's database.

为此我做了


  1. 使用UIImageJPEGReprenstation将图像转换为nsdata。

  2. 使用base64lib将nsdata转换为nstring。

问题在于我所拥有的nsstring是NSASCII编码的。

Problem here is that nsstring that I have is NSASCII encoded.

因此默认的开放ssl转换器无法读取文件并将其转换为正确的图像在服务器端。

So the default open ssl converters are not able to read the file and convert it into correct images on server side.

所以我需要的是

我的nsstring从nsdata创建的,不能使用nsascii或nsutf8等编码,因为图像数据是二进制的。

The nsstring that I have created from nsdata must not be encoded using nsascii or nsutf8 or something, as the image data is binary.

在服务器端,我必须从nsascii或我编码的任何方式将数据解码回二进制在客户端。但问题是我没有ascii解码的任何内置api。

On server side i must decode the data back to binary from nsascii or whatever way I have encoded on client side. But here the issue is I do not have any inbuilt api for ascii decoding.

推荐答案

为什么需要转换图像数据字符串数据?难道你不能用jpg数据(MIME图像/ jpeg)进行HTTP POST吗? 这篇文章向您展示了如何操作。

Why do you need to convert the image data to string data? Couldn't you just do an HTTP POST with jpg data (MIME image/jpeg)? This post shows you how to do it.

这篇关于无需编码即可将NSData转换为NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆