You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
//
|
|
// Created by Marco Schmickler on 21.03.15.
|
|
// Copyright (c) 2015 Marco Schmickler. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Alamofire
|
|
import SwiftyJSON
|
|
|
|
class UploadOperation: NSOperation {
|
|
let baseUrl: String
|
|
let data: NSData
|
|
let path: String
|
|
|
|
init(baseUrl: String, data: NSData, path: String) {
|
|
self.baseUrl = baseUrl
|
|
self.data = data
|
|
self.path = path
|
|
}
|
|
|
|
override func main() {
|
|
if self.cancelled {
|
|
return
|
|
}
|
|
|
|
let parameters = [
|
|
"file": NetData(data: data, mimeType: MimeType.Json, filename: path),
|
|
"name": path
|
|
]
|
|
|
|
print("PATH: \(path)")
|
|
|
|
let urlRequest = urlRequestWithComponents(baseUrl, parameters: parameters)
|
|
Alamofire.upload(urlRequest.0, data: urlRequest.1)
|
|
|
|
// success: todo set url to item
|
|
|
|
// .progress {
|
|
// (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
|
|
// print("progress : \(totalBytesWritten) / \(totalBytesExpectedToWrite)")
|
|
// }
|
|
.response { (request, response, data, error) in
|
|
if let d = data {
|
|
let datastring = NSString(data: d, encoding:NSUTF8StringEncoding)
|
|
print("d \(datastring)")
|
|
}
|
|
if let e = error {
|
|
print("e \(e)")
|
|
}
|
|
}
|
|
}
|
|
}
|