1

I try to send big video files with the OutputStream(url: payloadFileURL, append:) function but I have a code status 500. (I precise that when I send 1gb, 2gb it works like a charm)

Here is the entire code: Send big files with OutputStream

private func buildPayloadFile(videoFileURL: URL, boundary: String, fileName: String, eventId: Int, contactId: Int, type: Int) throws -> URL {
    let mimetype = "video/mp4"

    let payloadFileURL = URL(fileURLWithPath: NSTemporaryDirectory())
        .appendingPathComponent(UUID().uuidString)

    guard let stream = OutputStream(url: payloadFileURL, append: false) else {
        throw UploadError.unableToOpenPayload(payloadFileURL)
    }

    stream.open()

    //define the data post parameter
    stream.write("--\(boundary)\r\n")
    stream.write("Content-Disposition:form-data; name=\"eventId\"\r\n\r\n")
    stream.write("\(eventId)\r\n")

    stream.write("--\(boundary)\r\n")
    stream.write("Content-Disposition:form-data; name=\"contactId\"\r\n\r\n")
    stream.write("\(contactId)\r\n")

    stream.write("--\(boundary)\r\n")
    stream.write("Content-Disposition:form-data; name=\"type\"\r\n\r\n")
    stream.write("\(type)\r\n")

    stream.write("--\(boundary)\r\n")
    stream.write("Content-Disposition:form-data; name=\"file\"; filename=\"\(fileName)\"\r\n")
    stream.write("Content-Type: \(mimetype)\r\n\r\n")
    if stream.append(contentsOf: videoFileURL) < 0 {
        throw UploadError.unableToOpenVideo(videoFileURL)
    }
    stream.write("\r\n")

    stream.write("--\(boundary)--\r\n")
    stream.close()

    return payloadFileURL
}

Any ideas?

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • a 500 error is an error on the server side, you could be exceeding the max post size or something – Scriptable Dec 18 '18 at 13:02
  • @Scriptable I tried with Postman directly without passing with iOS, it works like a charm with 5Gb file. There is something missing in iOS I think? – ΩlostA Dec 18 '18 at 13:03
  • if thats the case, then yes, something in your iOS code is not correct and causing an error on the server. – Scriptable Dec 18 '18 at 13:05
  • @Scriptable But why with 3Gb and not 2Gb? It is strange ? – ΩlostA Dec 18 '18 at 13:08
  • 1
    not sure tbh, that is strange. I would just try to mimic your Postman request as much as possible. compare the code... postman can actually generate the code for this in Swift – Scriptable Dec 18 '18 at 13:12
  • Oh ok, I am going to check that code with Postman – ΩlostA Dec 18 '18 at 13:15

1 Answers1

1

Error 500 means a server side problems. There can be several reasons:
- server side configuration
- server disk space
- problem with server implementation

Please also check your client code:
- Content Type
- Mime type
- Enough space on device. Because of this big file, it will need more space on the device to store in memory during "cache"

dt dino
  • 1,194
  • 6
  • 19
  • Exact, that was the device space problem! The code status 500 internal server error is very misleading... – ΩlostA Dec 18 '18 at 16:38
  • 1
    If it is that kind of problem, your client code might have sent truncated packets to the server – dt dino Dec 19 '18 at 09:03