Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload file - dataFromParameters function #23

Closed
marko85to opened this issue Oct 20, 2014 · 5 comments
Closed

Upload file - dataFromParameters function #23

marko85to opened this issue Oct 20, 2014 · 5 comments

Comments

@marko85to
Copy link

Hi,
I'm getting an error when i'm trying to upload a file using file path.

This is the code i'm running:

let fileUrl = NSURL.fileURLWithPath("/Users/Marco/Documents/test.m4a")
var request = HTTPTask()

request.POST("http://www.example.com", parameters: ["p1": "v1", "p2": "v2", "file": HTTPUpload(fileUrl: fileUrl!)], success: {(response: HTTPResponse) -> Void in
            if response.responseObject != nil {
                let data = response.responseObject as NSData
                let str = NSString(data: data, encoding: NSUTF8StringEncoding)
                println("response: \(str)")
            }
            },failure: {(error: NSError) -> Void in
                println(error)
 })

Then, from the 'HTTPRequestSerializer' class, from the 'dataFromParameters' function, I get an error in the following line:
mutData.appendData(upload.data!)
which prints: fatal error: unexpectedly found nil while unwrapping an Optional value

I suppose this is happening because the function is expecting a data blob file, which has a different constructor in HTTPUpload class.

convenience init(data: NSData, fileName: String, mimeType: String) {
        self.init()
        self.data = data
        self.fileName = fileName
        self.mimeType = mimeType
    }
@daltoniam
Copy link
Owner

Thanks for reporting this, it was broken 😄 . I just merged the xCode 6.1 branch that had the fix in it. Let me know if that fixes the issue.

@marko85to
Copy link
Author

Thanks for the fix!

I get a new error from the following function:

func newRequest(url: NSURL, method: HTTPMethod) -> NSMutableURLRequest {
        var request = NSMutableURLRequest(URL: url, cachePolicy: cachePolicy, timeoutInterval: timeoutInterval)
        request.HTTPMethod = method.rawValue

HTTPMethod does not have a member named 'rawValue'

Same error is found in createRequest function.

@daltoniam
Copy link
Owner

This is probably because you are still using xCode 6. xCode 6.1 was released a few days ago, and they changed the rawValue() method into a property of rawValue. Upgrading to xCode 6.1 should resolve the issue.

@marko85to
Copy link
Author

I thought it might be a problem with the version but I have already updated. It might be a problem with my machine then. Thank you very much for your support!

@daltoniam
Copy link
Owner

Welcome and thanks again!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants