Xojo.Net.HTTPSocket import file corrupt

  1. 2 weeks ago

    Claude S

    Apr 11 Pre-Release Testers, Xojo Pro

    I use a httpsocket to import a pdf from my server to a iPhone. I use this code:

    Sub getDocument(urlDoc As Text, outputFile As Xojo.IO.FolderItem )

    Declare Function CFURLCreateStringByAddingPercentEscapes Lib "Foundation" (allocator As Ptr, origString As CFStringRef, charactersToLeaveUnescaped As CFStringRef, legalURLCharactersToBeEscaped As CFStringRef, encoding As UInt32) As CFStringRef

    Dim encodedURL As Text
    encodedURL = CFURLCreateStringByAddingPercentEscapes(Nil, urlDoc, Nil, Nil, &h08000100)
    // Call to get document
    Self.Send("GET", encodedURL, outputFile)

    End Sub

    I have another code in the " FileReceived" of the socket Event to write the imported file on the SpecialFolder.Documents of my app on the mobile device.
    The document I import is a PDF file. The importation works fine.

    When I open this document in my app, I call adobe acrobat reader. There is always this message that appears:
    " Impossible to open this document, It is corrupted".

    If I copy myself the same PDF using iTunes on the mobile device into the app, I open it using my app and it works fine.

    Is there a problem when the file is imported from the server?

  2. Deleted 2 weeks ago by Michel B
  3. Jérémie L

    Apr 11 Pre-Release Testers, Xojo Pro Europe (France)
    Edited 2 weeks ago by Jérémie L

    Hi,

    What is the httpstatus in the FileReceived event ?
    Is file.length consistent with the PDF file size in the FileReceived event ?

    How do you call adobe acrobat reader ?
    Where is the pdf file stored on the device ?
    Are you sure Adobe Acrobat Reader has read access to the file ?

    Have you tried displaying the PDF in a iOSHTMLViewer ?

  4. 5 days ago

    Claude S

    Apr 18 Pre-Release Testers, Xojo Pro

    What is the httpstatus in the FileReceived event ? 200 which means success

    Is file.length consistent with the PDF file size in the FileReceived event ? No. Original document 44 Ko
    Downloaded doc. 41 Ko
    Have you tried displaying the PDF in a iOSHTMLViewer ? Yes but did not work.
    Where is the pdf file stored on the device ? SpecialFolder.Documents
    Are you sure Adobe Acrobat Reader has read access to the file ? Yes

    How do you call adobe acrobat reader ?
    I used your code from a previous post:

    //create the view controller
    using Extensions
    using Foundation
    using UIKit
    dim controller as UIActivityViewController
    Dim fileArr As NSArray = NSArray.CreateWithObject(NSURL.URLWithString(encodedUrl))
    controller = new UIActivityViewController(fileArr, nil)
    Dim excludeArr As NSArray = NSArray.CreateWithObject( new NSString(UIActivity.UIActivityTypePrint))
    excludeArr = excludeArr.ArrayByAddingObject(new NSString(UIActivity.UIActivityTypeCopyToPasteboard))
    excludeArr = excludeArr.ArrayByAddingObject(new NSString(UIActivity.UIActivityTypeMail))
    controller.excludedActivityTypes = excludeArr
    //present with nil completion handler
    self.PresentViewController(controller, True, nil)

    Because the length of the file is not the same as the original, I am wondering why it cuts it???????

    Thanks for help.

  5. 3 days ago

    Greg O

    Apr 19 Xojo Inc Somewhere near Raleigh, NC

    The file may not be completely written in the FileReceived event. Try using Xojo.Timer.CallLater to call another method to process the file.

or Sign Up to reply!