文件上传下载

网络
文件上传下载

小文件下载

如果文件比较小,下载方式会比较多

p直接用NSData的+ (id)dataWithContentsOfURL:(NSURL *)url;
p利用NSURLConnection发送一个HTTP请求去下载
p如果是下载图片,还可以利用SDWebImage框架

HTTP Range的示例

通过设置请求头Range可以指定每次从网路下载数据包的大小

Range示例

bytes=0-499  从0到499的头500个字节

bytes=500-999  从500到999的第二个500字节

bytes=500-  从500字节以后的所有字节

bytes=-500  最后500个字节

bytes=500-599,800-899  同时指定几个范围

Range小结

-  用于分隔

p前面的数字表示起始字节数
p后面的数组表示截止字节数,没有表示到末尾

,  用于分组,可以一次指定多个Range,不过很少用

第三方解压缩框架——SSZipArchive

下载地址:https://github.com/samsoffes/ssziparchive

注意:需要引入libz.dylib框架

// Unzipping

NSString *zipPath = @"path_to_your_zip_file";

NSString *destinationPath = @"path_to_the_folder_where_you_want_it_unzipped";

[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];

// Zipping

NSString *zippedPath = @"path_where_you_want_the_file_created";

NSArray *inputPaths = [NSArray arrayWithObjects:

                       [[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpg"],

                       [[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"jpg"]

                       nil];

[SSZipArchive createZipFileAtPath:zippedPath withFilesAtPaths:inputPaths];

multipart/form-data格式小结

原文地址:https://www.cnblogs.com/niexiaobo/p/4888698.html