Jump to content

GetRemoteFile Method problem - doesn't download photo from long URL


Recommended Posts

Posted (edited)

Hi, as the title says, I'm trying to download photos from different URLs. But I have a problem when the URL is too long I noticed, then it doesn't download (probably when its length it longer than 256?). Anyone can help me solving this problem? Are there maybe some functions that could help me download photos from big URLs? I tried using RenderMan's GetFileURL, I attached it below
 

(defun GetFileURL  (url path / utilObj tempPath newPath)
 ;; © RenderMan 2011, CADTutor.net
 ;; Example: (GETFILEURL "https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf" (getvar 'dwgprefix))
 (vl-load-com)
 (setq utilObj (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))))
 (if (= :vlax-true (vla-isurl utilObj url))
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'vla-GetRemoteFile
           (list utilObj url 'tempPath :vlax-true))
        )
     (prompt "\n  <!>  Error Downloading File From URL  <!> ")
     (progn
       (if (findfile
             (setq newPath
                    (strcat path
                            (vl-filename-base url)
                            (vl-filename-extension url))))
         (vl-file-rename
           newPath
           (setq voidPath
                  (strcat
                    (vl-filename-directory newPath)
                    "\\void_"
                    (vl-filename-base newPath)
                    "_"
                    (menucmd
                      "M=$(edtime,$(getvar,date),YYYY-MO-DD-HH-MM-SS)")
                    (vl-filename-extension newPath)))))
       (vl-file-copy tempPath newPath)
       (vl-file-delete tempPath))
  )
   (prompt "\n  <!>  Invalid URL  <!> "))
 (vl-catch-all-apply 'vlax-release-object (list utilObj))
 (princ)
)

 

Edited by lastknownuser
  • lastknownuser changed the title to GetRemoteFile Method problem - doesn't download photo from long URL
Posted

right click photo, 'save as' to your computer....

 

Or ask the photo owner to e-mail it to you?

Posted

I created a lisp that selects area and inserts a scaled picture from given URL to it. @Steven P I know I could do it that way but I'm trying to make my work easier and faster, as I have to insert a lot of these images.
I read moments ago that there is a limitation for path length, but doubt it can be changed, or maybe it can? Or any other idea to solve this would be welcome.

Posted (edited)

need a url for testing to see whats going on.

 

Does it give the error

 <!>  Error Downloading File From URL  <!>

or the file isn't in the void folder?

 

 

-edit

also make sure its a valid url

 

Edited by mhupp
Posted

Here is a test URL, I made it longer by adding some duplicates:

https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?request=getmap&service=wms&service=wms&service=wms&service=wms&service=wms&service=wms&service=wms&BBOX=-90,-180,90,360&crs=EPSG:4326&format=image/jpeg&layers=gebco_latest&width=1200&height=600&version=1.3.0

I noticed that 280 is the limit, everything beyong that gives me the mentioned error 

<!>  Error Downloading File From URL  <!>

 

Posted
22 minutes ago, lastknownuser said:

 noticed that 280 is the limit, everything beyong that gives me the mentioned error

 

This is not the case.  the lisp is segmenting the url to create the file name. so anything after the last / is consider the file name. for that url its "jpeg&layers=gebco_latest&width=1200&height=600&version=1.3"

You have to feed it url's that end with the file name like the example with the pdf

 

BricsCAD ends up creating a 0 kb file tho.

 

  • Agree 1
Posted

Okay, but I did several tests with different links that had different position of last "\", I personally have a problem because I'm using password protected wms server, so it has a long password in link which makes it so long, too long apparently. But all links that were around max. 270 length I downloaded, those that were around 290 and more gave me error. I'd really like to solve this if possible, any other info or help appriciated!

Posted (edited)

Again I don't think its a length issue.  unless your running 32 bit window maybe?

 

do a test

(setq url "long url here")

 

test to see if storing the full url by either

 

(princ url) or

(alert url) this will only show the end tho.

 

Also if their are spaces might need to change them to %20

 

(while (vl-string-search " " url)
  (setq url (vl-string-subst "%20" " " url))
)

 

Edited by mhupp
it is a length issue with vla-getremotefile
Posted (edited)

I'm running 64 bit, tested on 2 computers (Autocad 2018 and 2019). I am doing it that way, combining few strings to save url string as a variable, it is normally stored and can be seen if called. For last example strlen gave me value of 291. No spaces in url, it is just like the one, different parameters connected with "&" symbol. And it does not work.

I tried to debug it as much as I could, but the error is always here, it gives T if url length is longer than 280 or something like that

(vl-catch-all-error-p
         (vl-catch-all-apply
           'vla-GetRemoteFile
           (list utilObj url 'tempPath :vlax-true))
        )


EDIT: for strlen 285 I get nil, for 286 and up I get T, no matter on which side of "/" I add or remove characters.

Edited by lastknownuser
Posted

Looks like vla-getrermotefile has a read length of 285 then.

Posted (edited)

I've tried this code and a couple of others using the same, they won't work at all for me, possibly the company firewall is blocking everything, possibly something else (suspect firewall since this won't go through the company virus checker I reckon?)

 

Anyway, are all the files you are wanting to download from the same source, or are they from different sources? Might be a long shot of course but might be one is a trusted source, another isn't. If you right click and copy via windows explorer that might be checked by the virus checker and so is OK to copy that way. Just a thought.

 

Years ago when I was first taught programming we had strings and longstrings, (16 bits and 32 or 64 can't remember), or was is string and double - can't remember now - but not for the last lots of years. OK so Vla-GetRemoteFile is a few years old now but I am surprised it has a length limitation.

 

 

EDIT - Ahh Secureremoteaccess system variable......

Edited by Steven P
Posted

I tried changing SECUREREMOTEACCESS variable, doesn't change anything. And the photos are all from the same source. It must be the length limitation, because I downloaded the same photo and added just one by one "&" symbol to link until it length was over 285, and then I got an error. Don't think it can be done with Vla-GetRemoteFile, unless the length limit can be somehow changed.

Also I found a thread with the same problem, and length of not working link is 286...unfortunately no solution was posted
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-getremotefile-automation-error-inet-not-a-valid-url/td-p/1299507

  • Like 1
  • Agree 1
Posted

Always looking to see if it something else,.

 

Wonder if there is anther way to do this then? copy and paste a file, tried vl-file-copy just then but that didn't work for me, is there a vl-cmdf function that might work?

Posted (edited)

I think you will have to do external to Autocad in saying that using Shell and some OS function to copy to clipboard then paste image. I have found "powershell" very useful for OS type stuff. It has lots of help examples , I found out how to unzip files from Autocad. Open a web page image then copy. Sorry not much more than that. Not sure if you can map a web Url to a variable ie shorten the path, like you can drives. Any body out there from the Java world. 

 

A google https://adamtheautomator.com/powershell-copy-to-clipboard/

Edited by BIGAL
  • Like 2
  • Agree 1
Posted

An unzip example.

 

(setq filename (getfiled "Select the File \"CAD-TOOLS-SEP-2022\"" "" "ZIP" 16))

; unzip
(startapp (strcat "powershell -command Expand-Archive -Path '" filename "' -DestinationPath 'C:/CAD-TOOLS' -FORCE"))
(alert "programs unzipped to C:/CAD-TOOLS")

 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...