Flight Upload API test:

User token:

Appname:

Appversion:

Appkey:

File (txt/txt.gz):



HTML Source:

<form action="https://api.airdata.com/flight_upload" method="post" enctype="multipart/form-data">
    <input type="text" name=usertoken>
    <input type="text" name=appname>
    <input type="text" name=appversion>
    <input type="text" name=appkey>
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>


Sample code - Android Java App

// Compress to .gz
gzipFile(uploadFile.toString(), compressedFilename.toString());
// construct the upload URL
String versionName = getAppVersionName(ctx);
String requestURL = "https://api.airdata.com/flight_upload?appkey=<YOUR_APP_KEY>&usertoken=" + userToken + "&appname=my_app_android&appversion=" + versionName;

try {
    String charset = "UTF-8";
    MultipartUtility multipart = new MultipartUtility(requestURL, charset);

    multipart.addHeaderField("User-Agent", "Your app name user agent 1.0");
    multipart.addFilePart("file", compressedFile);
    List<String> response = multipart.finish();

    // Parse JSON response here
    if (..success..) {
        // Save that this file was uploaded successfully
        // so it does not try to upload it again in the future
    } else {
        // handle error - can try again later
    }
} catch (UnknownHostException ex) {
    System.err.println(ex);
    // handle error - can try again later
} catch (IOException ex) {
    System.err.println(ex);
    // handle error - can try again later
}
compressedFile.delete();		// cleanup
The MultipartUtility class is based on the following, with the addition of javax.net.ssl:
https://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically




Sample code - iOS Swift App

let urlString = "https://api.airdata.com/flight_upload?appkey=<YOUR_APP_KEY>&usertoken=\(HDtoken)&appname=my_app_ios&appversion=\(appVersion)" as String
let url = URL(string: urlString.addingPercentEscapes(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: url!)
let boundary = "Boundary-\(UUID().uuidString)"
request.httpMethod = "POST"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
let body = NSMutableData()

body.append("--\(boundary)\r\n".data(using: String.Encoding.utf8)!)
body.append("Content-Disposition:form-data; name=\"file\"; filename=\"\(MyFile)\"\r\n".data(using: String.Encoding.utf8)!)
body.append("Content-Type: image/png\r\n\r\n".data(using: String.Encoding.utf8)!)
body.append(data)
body.append("\r\n".data(using: String.Encoding.utf8)!)
body.append("--\(boundary)--\r\n".data(using: String.Encoding.utf8)!)
request.httpBody = body as Data
let (data, response, error) = URLSession.shared.synchronousDataTaskWithRequest(request)
if let error = error {
    print(error.localizedDescription)
    DispatchQueue.main.async {
        self.SyncResultsView.text = "Unable to connect"
    }
} else {
    let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)

    // Parse JSON response here
    if(..success..){
        print("Uploaded OK \(MyFile)")
    } else {
        DispatchQueue.main.async {
            self.SyncResultsView.text = "Unable to upload to Airdata, check Token"
        }
        DispatchQueue.main.async {
            self.SyncNowButton.setTitle("Stopping...", for: UIControlState())
        }
        sleep(5)
    }
}