Jump to content

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


Recommended Posts

Posted

Hey @lastknownuser,

 

Recently, about 3 months ago, I had the same problem when I'm inputing list of coordinates (not URL as in your situation), searched and find a Lee Mac "Edit Box", which allows you to input long strings. I had a list of coordinates which are above 256 chars.

 

This is the one example:

7460341.30731,4952812.58478;7460339.16188,4952812.45867;7460333.74101,4952811.59474;7460328.22497,4952810.11139;
7460323.35995,4952808.29150;7460318.44870,4952805.80094;7460313.75538,4952802.90348;7460309.19004,4952799.30897;
7460305.28488,4952795.45723;7460301.74612,4952791.12873;7460298.20849,4952785.72050;7460295.71526,4952780.89565;
7460293.55197,4952775.26691;7460292.30544,4952770.37190;7460291.35311,4952765.03096;7460291.05343,4952759.58589;
7460291.19119,4952754.64824;7460291.75286,4952750.23612;7460292.42872,4952746.76434;7460293.64752,4952742.33862;
7460295.20497,4952738.10457;7460297.02929,4952734.27697;7460299.65275,4952729.68333;7460302.46737,4952725.71176;
7460306.13292,4952721.40599;7460309.29287,4952718.19119;7460312.56612,4952715.17075;7460317.95547,4952710.72313;
7460321.66649,4952715.29556;7460317.95030,4952718.31123;7460313.13577,4952722.67921;7460309.05602,4952727.01792;
7460306.78887,4952729.72010;7460304.39344,4952733.27336;7460302.48223,4952736.61070;7460300.79795,4952740.20136;
7460299.37427,4952743.80307;7460298.06429,4952748.62802;7460297.35221,4952752.68302;7460296.90305,4952757.97551;
7460297.08817,4952762.50290;7460297.55584,4952766.67150;7460298.71749,4952771.67261;7460299.91468,4952775.42996;
7460302.30991,4952780.80184;7460304.42519,4952784.56529;7460307.59105,4952789.04166;7460311.23877,4952792.96725;
7460314.44326,4952795.83664;7460318.53995,4952798.86494;7460323.38912,4952801.65306;7460328.72038,4952804.00840;
7460332.52600,4952805.13357;7460337.53928,4952806.27385;7460341.61353,4952806.58608;7460341.30731,4952812.58478;

 

This is the link: https://www.lee-mac.com/editbox.html

 

On 05/10/2022 at 14:53, lastknownuser said:

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

 

When input your example (from quoted above), I get a full length of URL, which stored in str1 variable (picture 1).

 

image.thumb.png.887bec2df249449c3916bf1dfe482f29.png

Maybe this can also help you for your solution.

 

Best regards.

Posted
1 hour ago, GLAVCVS said:

With 'winHTTPRequest' you should have no problems with the URL string length.
Try this

 

(defun descargaWEBarch (URL archLocal / arch flujo objHTTP guardar)
  (defun guardar (idArchivo archDestino / arch flujo)
    (if	(setq arch (vlax-create-object "ADODB.Stream"))
      (progn
	(setq flujo
	       (vl-catch-all-apply
		 (function (lambda ()
			     (vlax-put arch "Type" 1)
			     (vlax-invoke arch "Open")
			     (vlax-invoke-method
			       arch
			       "Write"
			       idArchivo
			     )
			     (vlax-invoke
			       arch
			       "SaveToFile"
			       archDestino
			       2
			     )
			   )
		 )
	       )
	)
	(vlax-release-object arch)
	(if (not (vl-catch-all-error-p flujo))
	  archDestino
	)
      )
    )
  )
  (if (vl-filename-directory archLocal)
    (if	(setq objWHTTP (vlax-create-object "WinHTTP.WinHTTPRequest.5.1"))
      (progn
	(setq
	  flujo
	   (vl-catch-all-apply
	     (function
	       (lambda ()
		 (vlax-invoke-method objWHTTP "Open" "GET" URL :vlax-false)
		 (vlax-invoke objWHTTP "Send")
		 (if (= (vlax-get-property objWHTTP "Status") 200)
		   (vlax-get-property
		     objWHTTP
		     "ResponseBody"
		   )
		 )
	       )
	     )
	   )
	)
	(vlax-release-object objWHTTP)
	(if (and flujo (not (vl-catch-all-error-p flujo)))
	  (guardar flujo archLocal)
	)
      )
    )
    (progn
      (princ "\n*** ERROR: El directorio especificado no existe ***")
      nil
    )
  )
)

 


Thanks, but did you test it, does it work for you?
I tried this and nothing is saved in C for me.

(DESCARGAWEBARCH "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" "C:\\")


@Saxlle Thanks for the input, but the string variable length itself isn't the problem, its the GetRemoteFile not accepting URL string longer than 285. I can save the long string as variable normally without a problem if thats what you meant.

Posted (edited)

Sure it works.
I've tested it with URLs of 400 characters and more.
But when specifying the destination file you must make sure that you have the necessary write permissions on the destination directory.
Windows may not let you write to 'C:'

For the avoidance of doubt choose the 'Documents' folder

Edited by GLAVCVS
Posted
56 minutes ago, GLAVCVS said:

Sure it works.
I've tested it with URLs of 400 characters and more.
But when specifying the destination file you must make sure that you have the necessary write permissions on the destination directory.
Windows may not let you write to 'C:'

For the avoidance of doubt choose the 'Documents' folder


Weird, for me it does not. I tested save paths C, D, Documents. I mean I am in administrator mode, don't know why it wouldn't let me write, I can write other files with lisp to that paths. Maybe its some kind of Windows problem with WinHttpRequest (I'm using Windows 10).

Posted

It's clear that you have some problem with the writing permissions.

Try writing to a pendrive

Posted (edited)
2 hours ago, lastknownuser said:

Thanks for the input, but the string variable length itself isn't the problem, its the GetRemoteFile not accepting URL string longer than 285. I can save the long string as variable normally without a problem if thats what you meant.

Yes, meant on that.

 

Give a try with this, one of solutions (it works on Windows OS):

 

(defun c:GetFileURL ( / directory str1 directoryPath folder filename extension withOutDot clipvalue)
  
  (defun LM:editbox ( str / han )
    (and (< 0 (setq han (load_dialog "acad")))
	 (new_dialog  "acad_txtedit" han)
	 (set_tile    "text_edit"    str)
	 (action_tile "text_edit" "(setq str $value)")
	 (if (zerop (start_dialog)) (setq str nil))
	 )
    (if (< 0 han) (unload_dialog han))
    str
    )
    
  (setq str1 (LM:editbox ""))
  (setq filename (vl-filename-base str1)
	extension (vl-filename-extension str1)
	withOutDot (substr extension (+ (vl-string-position (ascii ".") extension nil) 2))
	)
  
  (setq directory (getfiled "File save destination" filename withOutDot 1))
  
  (setq directoryPath (vl-filename-directory directory)
	folder (substr directoryPath (+ (vl-string-position (ascii "\\") directoryPath nil) 2))
	)
  
  (setq clipvalue (strcat (substr directoryPath 1 2)  " && cd " folder " && curl " str1 " -o " filename extension))
  (command "shell" clipvalue)
  )

 

First copy link from browser, run lisp, paste link, choose desire destination and folder and save it. I'v tried with different save location (for eg. D:\\New Folder\\Picture, not C:\\ partition), after input a link with image or file (pdf) and choose "save location" and it appears in desired folder. 

 

Tested on this links: 

-  https://damassets.autodesk.net/content/dam/autodesk/www/products/autocad/fy24/toolsets/map-3d/autocad-map-3d-toolset-large-1920x1080-v2.jpg

-  https://damassets.autodesk.net/content/dam/estore/customer-service/AutoCAD_Shortcuts_11x8.5_MECH-REV.pdf (from your post)

 

Note: If your opening some pdf files with extensions in browser, you need to find begining link with https:// .

 

Best regards.

Edited by Saxlle
Posted

The final check can be done with the 'guardar' function.
This function is only executed if the file has been downloaded successfully.
I have slightly modified the code to display a message in this case.

However, Saxlle's option may be interesting.

 

(defun descargaWEBarch (URL archLocal / arch flujo objHTTP guardar)
  (defun guardar (idArchivo archDestino / arch flujo)
    (if	(setq arch (vlax-create-object "ADODB.Stream"))
      (progn
	(setq flujo
	       (vl-catch-all-apply
		 (function (lambda ()
			     (vlax-put arch "Type" 1)
			     (vlax-invoke arch "Open")
			     (vlax-invoke-method
			       arch
			       "Write"
			       idArchivo
			     )
			     (vlax-invoke
			       arch
			       "SaveToFile"
			       archDestino
			       2
			     )
			   )
		 )
	       )
	)
	(vlax-release-object arch)
	(if (not (vl-catch-all-error-p flujo))
	  archDestino
      (alert "Error: The file was downloaded but not could be written") 
	)
      )
    )
  )
  (if (vl-filename-directory archLocal)
    (if	(setq objWHTTP (vlax-create-object "WinHTTP.WinHTTPRequest.5.1"))
      (progn
	(setq
	  flujo
	   (vl-catch-all-apply
	     (function
	       (lambda ()
		 (vlax-invoke-method objWHTTP "Open" "GET" URL :vlax-false)
		 (vlax-invoke objWHTTP "Send")
		 (if (= (vlax-get-property objWHTTP "Status") 200)
		   (vlax-get-property
		     objWHTTP
		     "ResponseBody"
		   )
		 )
	       )
	     )
	   )
	)
	(vlax-release-object objWHTTP)
	(if (and flujo (not (vl-catch-all-error-p flujo)))
	  (guardar flujo archLocal)
	)
      )
    )
    (progn
      (princ "\n*** ERROR: El directorio especificado no existe ***")
      nil
    )
  )
)

 

  • Like 1
Posted

Okay got it to work actually, so thanks for that, this will be useful to me. Problem was that my image did not have a extension in the link, had to manually set that up while saving.

Posted (edited)

Maybe you didn't call the function correctly.

The correct way to call the function could be:
(descargaWEBarch "https://www.webco.net/..." "c:\\image.jpg")
because the image to download from that URL is .jpg, of course

But remember that you must have write permissions on the destination directory. As I said, the ideal way to avoid this is to select the 'Documents' folder

Edited by GLAVCVS
  • Agree 1
Posted

I wrote you my example that I tried that did not work for me. Asked you does it work for you. You said that it works for you so that was my confusion, I though you tried that one. Image is not necessarily jpg. In my case I have to specify format in the link. For example GetRemoteFile downloads my file without extension in the defined folder path. Here with your function I have to specify folder path including the name and format. So yes I didn't call the function correctly. Thanks again

Posted

Oh
Then maybe I misunderstood you. Sorry.
In any case, I'm glad to hear that the problem has been resolved.

🙂

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...