Saving a Image file

MiServer is Dyalog's APL-based web development framework

Saving a Image file

Postby Gantois on Fri Jun 21, 2024 7:51 pm

Hellow, Good Afternoon!

I submited a img file(.png,.jpg) to server (apl 18.2 / MiServer):

<input type="file" id="imgFile" name="imgFile" accept="image/png, image/jpeg, image/bmp, image/gif" class="w3-margin-top et-text-azulmed">

The MiServer received with success in a two elements variable (imgFile). The first element is the file name and the second, the file content.

My difficult is How to save this file in a directory, for example: c:\Temp

Could somebody help me, please?

// Marco Gantois
Gantois
 
Posts: 89
Joined: Thu Apr 17, 2014 9:44 am

Re: Saving a Image file

Postby Brian|Dyalog on Fri Jun 21, 2024 8:02 pm

Hi Marco!

If I understand your question correctly, you should be able to do something along the lines of:
      (name content)←imgFile
tn←('c:\Temp\',name) ⎕NCREATE 0
content ⎕NAPPEND tn
⎕NUNTIE tn

You may need to add code to deal with if the file already exists - do you delete and overwrite, rename, etc?

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 120
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Saving a Image file

Postby Gantois on Sat Jun 22, 2024 11:14 am

Hello Brian,

You perfectly understood my question.
I already used ⎕ncreate ⎕nappend ... but not for image files.
Very simple solution. I have already implemented in my site.

Thanks!!!!
Cheers,
Marco Gantois
Gantois
 
Posts: 89
Joined: Thu Apr 17, 2014 9:44 am

Re: Saving a Image file

Postby Gantois on Sat Jun 22, 2024 4:25 pm

Hi Brian,

My site frequently replace images with the same file name (⎕NERASE / ⎕NCREATE) but the browsers do not recognize the new image unless the cache is cleared.

Do you known what could I do to solve this issue? Perhaps changing some file attribute after create it. If so, how could I do this by apl? Do you have any recommendation for this purpose, please?

Thanks
Cheers,
Marco Gantois
Gantois
 
Posts: 89
Joined: Thu Apr 17, 2014 9:44 am

Re: Saving a Image file

Postby Brian|Dyalog on Sat Jun 22, 2024 9:28 pm

Hi Marco,

There are a number of techniques to accomplish this. I found this on stackoverflow. I don't understand your specific use case well enough to recommend a particular technique, but that link should get you going. If you have further questions, it might help for you to send me a copy of your MiPage.

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 120
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Saving a Image file

Postby Gantois on Sun Jul 07, 2024 11:56 am

Hi Brian,
Thanks for the tips / instructions and the prompt return.

In my case we have thousand images with only a few differents names in differents paths.
I solved the issue complementing the <img src=" " > with (?v=',(⍕⎕ts)~' ') as following (used in a reading function / last line):

∇ src←SrcImg (idq nomarq);src
:If nomarq≡'imgconfig.png'
src←'/Img/',nomarq
:ElseIf '3'=1↑idq
src←'/Database/',idinstit,'/',idescola,'/IMG/',idq,'/',nomarq
:Else
src←'/Database/',(4↑idq),'/IMG/',idq,'/',nomarq
:EndIf
src←src,'?v=',(⍕⎕ts)~' '


Cheers,
Marco Gantois
Gantois
 
Posts: 89
Joined: Thu Apr 17, 2014 9:44 am


Return to MiServer

Who is online

Users browsing this forum: Google [Bot] and 1 guest