Trying to read a URL file with ReadFile

Just starting out? Need help? Post your questions and find answers here.
User avatar
T4r4ntul4
Posts: 132
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands
Contact:

Trying to read a URL file with ReadFile

Post 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())
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Trying to read a URL file with ReadFile

Post 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
User avatar
T4r4ntul4
Posts: 132
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands
Contact:

Re: Trying to read a URL file with ReadFile

Post by T4r4ntul4 »

thnx, problem solved!
Post Reply