Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Roman Busyghin
2009-08-03 19:06:59 +0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Ben Copsey
2009-08-04 12:17:22 +0100
Commit
8e07118df69ae205bac9621a2b0e101ffe211081
8e07118d
1 parent
9d072e27
MIME type defining feature for ASIFormDataRequest
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
17 deletions
Classes/ASIFormDataRequest.h
Classes/ASIFormDataRequest.m
Classes/ASIFormDataRequest.h
View file @
8e07118
...
...
@@ -30,4 +30,7 @@
// Add the contents of an NSData object to the request
-
(
void
)
setData
:(
NSData
*
)
data
forKey
:(
NSString
*
)
key
;
// Allows to specify content type of the file
-
(
void
)
setFileDataContainerObject
:(
id
)
data
fileName
:(
NSString
*
)
fileName
contentType
:(
NSString
*
)
contentType
forKey
:(
NSString
*
)
key
;
@end
...
...
Classes/ASIFormDataRequest.m
View file @
8e07118
...
...
@@ -46,20 +46,26 @@
-
(
void
)
setFile
:
(
NSString
*
)
filePath
forKey
:
(
NSString
*
)
key
{
if
(
!
fileData
)
{
fileData
=
[[
NSMutableDictionary
alloc
]
init
];
}
[
fileData
setValue
:
filePath
forKey
:
key
];
[
self
setRequestMethod
:
@"POST"
];
[
self
setFileDataContainerObject
:
filePath
fileName
:
@"file"
contentType
:
@"application/octet-stream"
forKey
:
key
];
}
-
(
void
)
setData
:
(
NSData
*
)
data
forKey
:
(
NSString
*
)
key
{
[
self
setFileDataContainerObject
:
data
fileName
:
@"file"
contentType
:
@"application/octet-stream"
forKey
:
key
];
}
-
(
void
)
setFileDataContainerObject
:
(
id
)
data
fileName
:
(
NSString
*
)
fileName
contentType
:
(
NSString
*
)
contentType
forKey
:
(
NSString
*
)
key
{
if
(
!
fileData
)
{
fileData
=
[[
NSMutableDictionary
alloc
]
init
];
fileData
=
[[
NSMutableDictionary
alloc
]
init
WithCapacity
:
0
];
}
[
fileData
setObject
:
data
forKey
:
key
];
[
self
setRequestMethod
:
@"POST"
];
NSDictionary
*
fileInfo
=
[
NSDictionary
dictionaryWithObjectsAndKeys
:
data
,
@"fileDataContainerObject"
,
contentType
,
@"contentType"
,
fileName
,
@"fileName"
,
nil
];
[
fileData
setObject
:
fileInfo
forKey
:
key
];
[
self
setRequestMethod
:
@"POST"
];
}
-
(
void
)
buildPostBody
...
...
@@ -95,19 +101,21 @@
}
// Adds files to upload
NSData
*
contentTypeHeader
=
[[
NSString
stringWithString
:
@"Content-Type: application/octet-stream
\r\n\r\n
"
]
dataUsingEncoding
:
NSUTF8StringEncoding
];
e
=
[
fileData
keyEnumerator
];
i
=
0
;
while
(
key
=
[
e
nextObject
])
{
NSString
*
fileName
=
@"file"
;
id
file
=
[
fileData
objectForKey
:
key
];
if
([
file
isKindOfClass
:[
NSString
class
]])
{
fileName
=
(
NSString
*
)
file
;
}
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"Content-Disposition: form-data; name=
\"
%@
\"
; filename=
\"
%@
\"\r\n
"
,
key
,
fileName
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
[
self
appendPostData
:
contentTypeHeader
];
NSDictionary
*
fileInfo
=
[
fileData
objectForKey
:
key
];
id
file
=
[
fileInfo
objectForKey
:
@"fileDataContainerObject"
];
NSString
*
contentType
=
[
fileInfo
objectForKey
:
@"contentType"
];
NSString
*
fileName
=
[
fileInfo
objectForKey
:
@"fileName"
];
NSString
*
contentTypeHeader
=
[
NSString
stringWithFormat
:
@"Content-Type: %@
\r\n\r\n
"
,
contentType
];
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"Content-Disposition: form-data; name=
\"
%@
\"
; filename=
\"
%@
\"\r\n
"
,
key
,
fileName
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
[
self
appendPostData
:[
contentTypeHeader
dataUsingEncoding
:
NSUTF8StringEncoding
]];
if
([
file
isKindOfClass
:[
NSString
class
]])
{
[
self
appendPostDataFromFile
:
file
Name
];
[
self
appendPostDataFromFile
:
file
];
}
else
{
[
self
appendPostData
:
file
];
}
...
...
Please
register
or
login
to post a comment