Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
white49
Alamofire
提交
9dc80efb
A
Alamofire
项目概览
white49
/
Alamofire
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Alamofire
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9dc80efb
编写于
3月 26, 2019
作者:
C
Christian Noon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored upload APIs for MultipartFormData to support custom boundaries
上级
218561de
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
19 deletion
+20
-19
Source/Alamofire.swift
Source/Alamofire.swift
+4
-1
Source/MultipartFormData.swift
Source/MultipartFormData.swift
+2
-1
Source/MultipartUpload.swift
Source/MultipartUpload.swift
+8
-12
Source/Session.swift
Source/Session.swift
+6
-5
未找到文件。
Source/Alamofire.swift
浏览文件 @
9dc80efb
...
...
@@ -337,6 +337,7 @@ public enum AF {
/// - Parameters:
/// - multipartFormData: The closure used to append body parts to the `MultipartFormData`.
/// - encodingMemoryThreshold: The encoding memory threshold in bytes. `10_000_000` bytes by default.
/// - fileManager: The `FileManager` instance to use to manage streaming and encoding.
/// - url: The `URLConvertible` value.
/// - method: The `HTTPMethod`, `.post` by default.
/// - headers: The `HTTPHeaders`, `nil` by default.
...
...
@@ -345,12 +346,14 @@ public enum AF {
/// - Returns: The created `UploadRequest`.
public
static
func
upload
(
multipartFormData
:
@escaping
(
MultipartFormData
)
->
Void
,
usingThreshold
encodingMemoryThreshold
:
UInt64
=
MultipartUpload
.
encodingMemoryThreshold
,
fileManager
:
FileManager
=
.
default
,
to
url
:
URLConvertible
,
method
:
HTTPMethod
=
.
post
,
headers
:
HTTPHeaders
?
=
nil
,
interceptor
:
RequestInterceptor
?
=
nil
)
->
UploadRequest
{
return
Session
.
default
.
upload
(
multipartFormData
:
multipartFormData
,
usingThreshold
:
encodingMemoryThreshold
,
fileManager
:
fileManager
,
to
:
url
,
method
:
method
,
headers
:
headers
,
...
...
@@ -381,7 +384,7 @@ public enum AF {
///
/// - Returns: The `UploadRequest` created.
@discardableResult
public
static
func
upload
(
multipartFormData
:
@escaping
(
MultipartFormData
)
->
Void
,
public
static
func
upload
(
multipartFormData
:
MultipartFormData
,
usingThreshold
encodingMemoryThreshold
:
UInt64
=
MultipartUpload
.
encodingMemoryThreshold
,
with
urlRequest
:
URLRequestConvertible
,
interceptor
:
RequestInterceptor
?
=
nil
)
->
UploadRequest
{
...
...
Source/MultipartFormData.swift
浏览文件 @
9dc80efb
...
...
@@ -100,7 +100,8 @@ open class MultipartFormData {
/// The boundary used to separate the body parts in the encoded form data.
public
let
boundary
:
String
private
let
fileManager
:
FileManager
let
fileManager
:
FileManager
private
var
bodyParts
:
[
BodyPart
]
private
var
bodyPartError
:
AFError
?
private
let
streamBufferSize
:
Int
...
...
Source/MultipartUpload.swift
浏览文件 @
9dc80efb
...
...
@@ -31,7 +31,7 @@ open class MultipartUpload {
lazy
var
result
=
Result
{
try
build
()
}
let
isInBackgroundSession
:
Bool
let
multipart
Builder
:
(
MultipartFormData
)
->
Void
let
multipart
FormData
:
MultipartFormData
let
encodingMemoryThreshold
:
UInt64
let
request
:
URLRequestConvertible
let
fileManager
:
FileManager
...
...
@@ -39,25 +39,21 @@ open class MultipartUpload {
init
(
isInBackgroundSession
:
Bool
,
encodingMemoryThreshold
:
UInt64
=
MultipartUpload
.
encodingMemoryThreshold
,
request
:
URLRequestConvertible
,
fileManager
:
FileManager
=
.
default
,
multipartBuilder
:
@escaping
(
MultipartFormData
)
->
Void
)
{
multipartFormData
:
MultipartFormData
)
{
self
.
isInBackgroundSession
=
isInBackgroundSession
self
.
encodingMemoryThreshold
=
encodingMemoryThreshold
self
.
request
=
request
self
.
fileManager
=
fileManager
self
.
multipart
Builder
=
multipartBuilder
self
.
fileManager
=
multipartFormData
.
fileManager
self
.
multipart
FormData
=
multipartFormData
}
func
build
()
throws
->
(
request
:
URLRequest
,
uploadable
:
UploadRequest
.
Uploadable
)
{
let
formData
=
MultipartFormData
(
fileManager
:
fileManager
)
multipartBuilder
(
formData
)
var
urlRequest
=
try
request
.
asURLRequest
()
urlRequest
.
setValue
(
f
ormData
.
contentType
,
forHTTPHeaderField
:
"Content-Type"
)
urlRequest
.
setValue
(
multipartF
ormData
.
contentType
,
forHTTPHeaderField
:
"Content-Type"
)
let
uploadable
:
UploadRequest
.
Uploadable
if
f
ormData
.
contentLength
<
encodingMemoryThreshold
&&
!
isInBackgroundSession
{
let
data
=
try
f
ormData
.
encode
()
if
multipartF
ormData
.
contentLength
<
encodingMemoryThreshold
&&
!
isInBackgroundSession
{
let
data
=
try
multipartF
ormData
.
encode
()
uploadable
=
.
data
(
data
)
}
else
{
...
...
@@ -69,7 +65,7 @@ open class MultipartUpload {
try
fileManager
.
createDirectory
(
at
:
directoryURL
,
withIntermediateDirectories
:
true
,
attributes
:
nil
)
do
{
try
f
ormData
.
writeEncodedData
(
to
:
fileURL
)
try
multipartF
ormData
.
writeEncodedData
(
to
:
fileURL
)
}
catch
{
// Cleanup after attempted write if it fails.
try
?
fileManager
.
removeItem
(
at
:
fileURL
)
...
...
Source/Session.swift
浏览文件 @
9dc80efb
...
...
@@ -326,22 +326,23 @@ open class Session {
interceptor
:
RequestInterceptor
?
=
nil
)
->
UploadRequest
{
let
convertible
=
ParameterlessRequestConvertible
(
url
:
url
,
method
:
method
,
headers
:
headers
)
return
upload
(
multipartFormData
:
multipartFormData
,
let
formData
=
MultipartFormData
(
fileManager
:
fileManager
)
multipartFormData
(
formData
)
return
upload
(
multipartFormData
:
formData
,
usingThreshold
:
encodingMemoryThreshold
,
with
:
convertible
,
interceptor
:
interceptor
)
}
open
func
upload
(
multipartFormData
:
@escaping
(
MultipartFormData
)
->
Void
,
open
func
upload
(
multipartFormData
:
MultipartFormData
,
usingThreshold
encodingMemoryThreshold
:
UInt64
=
MultipartUpload
.
encodingMemoryThreshold
,
fileManager
:
FileManager
=
.
default
,
with
request
:
URLRequestConvertible
,
interceptor
:
RequestInterceptor
?
=
nil
)
->
UploadRequest
{
let
multipartUpload
=
MultipartUpload
(
isInBackgroundSession
:
(
session
.
configuration
.
identifier
!=
nil
),
encodingMemoryThreshold
:
encodingMemoryThreshold
,
request
:
request
,
fileManager
:
fileManager
,
multipartBuilder
:
multipartFormData
)
multipartFormData
:
multipartFormData
)
return
upload
(
multipartUpload
,
interceptor
:
interceptor
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录