DaveP Posted January 29, 2016 Share Posted January 29, 2016 Simple problem - I'm trying to save an image* from an external API and PW's API names in for its URL. The derived filename is too long for my filesystem. Is there any way (an appropriate hook would be lovely) to rename it before it is initially saved? (Kinda like 'Save As') *The image is a static map thumbnail from http://www.mapquestapi.com/staticmap/#getplacemap and, with a real API key inserted and the file path tacked on the front, the path+filename chokes my dev machine. Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 Hi Dave, Custom Upload Names should take care of it: http://modules.processwire.com/modules/process-custom-upload-names/ EDIT: Otherwise take a look at hooking after: Pagefile::install - you can either pull the code from the hook from the above module if you'd like. Link to comment Share on other sites More sharing options...
DaveP Posted January 29, 2016 Author Share Posted January 29, 2016 @adrian, I did try Custom Upload Names, but it didn't seem to work on image files saved purely through the API. If it should do, then I will persevere with it some more. Any tips would be very welcome. Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 @adrian, I did try Custom Upload Names, but it didn't seem to work on image files saved purely through the API. If it should do, then I will persevere with it some more. Any tips would be very welcome. It should definitely work through the API - let me take a look to confirm that I didn't break that functionality at some point, or that there isn't an issue with it and PW 3.x or anything else amiss. Will get back to you shortly. Link to comment Share on other sites More sharing options...
kongondo Posted January 29, 2016 Share Posted January 29, 2016 Maybe something like this first, then you use PW API after that? 1 Link to comment Share on other sites More sharing options...
justb3a Posted January 29, 2016 Share Posted January 29, 2016 There is a method called setTargetFilename($filename), maybe this does the trick? (not tested, just one look inside the WireUpload class) 1 Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 Hi Dave - I just tested CUN again with an API upload and it's working fine - can you please post your API code so I can take a look. EDIT: This is what I am using: $page->of(false); $page->images->add("http://domain.com/the_image.png"); $page->save("images"); Link to comment Share on other sites More sharing options...
DaveP Posted January 29, 2016 Author Share Posted January 29, 2016 Adrian, I'm using a single image field so it's $p->of(false); $p->map_thumbnail = 'http://verylongurl.com?lotsofparameters=toolongfilename'; $p->save(); so it's slightly different. But the error is that PW can't move the file, so at least that suggests that it would work with a shorter file name. (Limit is ~260 characters.) Give me a moment to install the module again and I'll get back to you. Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 Ok, I just checked with a filename over 260 characters and it uploaded ok, but didn't get renamed by CUN. Not because of the length, but because the filename didn't end in .jpg, .png etc I just used this is a test: http://domain.com/image_name.png?test=565675765675675675625625625672567256256254672567256256256725167256526725672567253625679267829647218546152412346725876651266781624582678512676567247625875267456255269759766786736738673678467836782357653675438762354675375 I can take a look at making CUN support things like this if it would help. PS - it was actually renamed, but the "test=1267686....." remained on the end. Link to comment Share on other sites More sharing options...
DaveP Posted January 29, 2016 Author Share Posted January 29, 2016 (edited) Nope, still not working, with your $page->images->add() style coding. This is the error Error: Exception: Unable to copy: http://www.mapquestapi.com/staticmap/v4/getplacemap?key=myAPIKey&location=PR7%202EJ&size=250,250&type=map&zoom=15&imagetype=gif&showicon=purple_1 => D:/wamp/www/ss/site/assets/files/1026/getplacemap_key_myAPIKey_location_L4_0TH_size_250-250_type_map_zoom_15_imagetype_gif_showicon_purple_1.com_staticmap_v4_getplacemap_key_myAPIKey_location_L4_0TH_size_250_250_type_map_zoom_15_imagetype_gif_showicon_purple_1 (in D:\wamp\www\ss\wire\core\Pagefile.php line 117) As far as I can tell I set up your module correctly - enabled just for map_thumbnail field and renaming to just mapthumbnail as it is a singular field and there will only ever be one image. PW 2.7.2 in case I forgot to mention. <edit>Take out both API key mentions.</edit> Edited January 29, 2016 by DaveP Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 Ok, I just tested (got my own mapquest api key) and am getting the same error as you - this is something that will need to be dealt with before PW tries to sanitize the file - there is no file extension, so it doesn't know what it is. Either way, the error is coming before CUN gets a look in, so it won't help in this case. You could use wireUpload I guess, or maybe hook in earlier - perhaps Pagefile::filename - I'll keep digging. 1 Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2016 Share Posted January 29, 2016 Looks like I have tried to help someone with a similar situation before and they ended up using WireUpload: https://processwire.com/talk/topic/5490-hook-for-wireupload-filename-images/?p=53997 Does that help? 2 Link to comment Share on other sites More sharing options...
DaveP Posted January 29, 2016 Author Share Posted January 29, 2016 (edited) @Adrian Hmm, looks like a similar problem to sevarf2's. Late in the day here, so I'll revisit this over the weekend. @kongondo Would I be right in thinking that that method would entail an intermediate step, much like the one in the thread Adrian links to above? @justb3a Tried a few variations with your suggestion, but no joy. If the worst comes to the worst, I could just call a new image every page load. I was trying to do some local caching and play nice with MapQuest's API. <edit> Couldn't resist a bit more googling and http://stackoverflow.com/questions/10233577/create-image-from-url-any-file-type looks promising. No time to test now but I will report back at some point.</edit> Edited January 29, 2016 by DaveP 1 Link to comment Share on other sites More sharing options...
pkmarkosarnych Posted February 17, 2016 Share Posted February 17, 2016 I suggest to try a third party tool to bypass long path errors. I am also sceptic to these ways but it will help you. It is called Long Path Tool and allows you to manipulate with files regardless its path or name Link to comment Share on other sites More sharing options...
adrian Posted February 17, 2016 Share Posted February 17, 2016 @pkmarkosarnych - thanks for your input, but the software you are suggesting is not useful in this situation as the OP is trying to link to map file with many URL parameters and without an image file extension. Link to comment Share on other sites More sharing options...
DaveP Posted April 5, 2016 Author Share Posted April 5, 2016 Just for the record, I ended up using leaflet.js instead. Link to comment Share on other sites More sharing options...
DaveP Posted April 27, 2017 Author Share Posted April 27, 2017 On 4/5/2016 at 4:41 PM, DaveP said: Just for the record, I ended up using leaflet.js instead. Quitter! 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now