Page 1 of 1

Trying to read a URL file with ReadFile

Posted: Thu Mar 30, 2017 1:56 pm
by T4r4ntul4
Hey all,

Iam trying to read the file contents of a txt file from a URL, in the docs it says by ReadFile() that you can use a URL to read from.
I already discovered that i cant use a subdomain in the link, but to need use the full path to the file. Now i get errors, but other than that nothing really much happens.

What do i wrong?

I edited the example code for easier understanding:

Code: Select all

Procedure ReadCallback(Status, Filename$, File, Size)
  Debug "ReadCallback"
  
    If Status = #PB_Status_Loaded
      Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
      
      ; Read the first 10 lines
      ;
      While Eof(0) = 0 And NbLine < 10 
        Debug ReadString(0)            
        NbLine+1
      Wend
      
      CloseFile(0)
      
    ElseIf Status = #PB_Status_Error
      Debug "Error when loading the file: " + Filename$
    EndIf
  EndProcedure
  
  Procedure OpenFileRequesterCallback()
    Debug "OpenFileRequesterCallback"
    
    ;If NextSelectedFile()
      ;Debug "NextSelectedFile"
      ReadFile(0, "http://www.dppro.nl/timelinegen/TLG_Tutorial.txt", @ReadCallback() , #PB_File_Streaming)
    ;EndIf
  EndProcedure
  
;   Procedure ChooseFileEvent()
;     OpenFileRequester("*.txt", @OpenFileRequesterCallback())
;   EndProcedure
  
  OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
    ButtonGadget(0, 10, 10, 280, 30, "Choose a file...")
    
    BindGadgetEvent(0, @OpenFileRequesterCallback())

Re: Trying to read a URL file with ReadFile

Posted: Thu Mar 30, 2017 2:18 pm
by Peter
Browser-Console wrote:XMLHttpRequest cannot load http://www.dppro.nl/timelinegen/TLG_Tutorial.txt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:9081' is therefore not allowed access.
this may help: http://forums.spiderbasic.com/viewtopic ... 2110#p2110

Greetings ... Peter

Re: Trying to read a URL file with ReadFile

Posted: Thu Mar 30, 2017 5:59 pm
by T4r4ntul4
thnx, problem solved!