Store blob as file - blob

I am trying to save blob from a form as a file on my server without success:
<form method="post" name="myform" action="action.php">
<input type="hidden" name="urlAddress" id="mytext">
</form>
my mytext.value is set to some window.URL.createObjectURL(data);
Now, I am able to download or view this value from browser: console.log(mytext.value) gives 'blob:https://127.0.0.2/e2f169ab-6165-4466-880e-30642e8c8770'
From PHPside, I use $url=$_POST['urlAddress'];
Questions :
1/ how to save that file (which I am actually able to save from browser!) with php to server disk?
2/ is it possible to use phpmailer to directly send this blob as attached file?
Thanks a lot for any help,
--Fred

Related

vue file input set default value when v-model is not allowed

Maybe someone gives me advise how to set default value for input type files in vue (i have file name, but I think I need something more)? I know that v-model is senseless, so I have no idea how to do it, and can't found some solutions.
You cannot set default value to file inputs. You just display file info in separate element and use file input just to upload new files.
E.g.
<div>
{{file.name}}
<!-- Just display the name of the existing file -->
<button #click.prevent="removeFile(file)">Remove</button>
<!-- button to delete existing file -->
</div>
<input type="file" #change="handleUpload">
<!-- Show input just to upload new file and replace the old one -->
Thank you for your answers. Then I try to use v-model there I have error v-model is not allowed here. To be honest there was problem with validation during edit. File input is empty, because I can't preaload data, and validation not allowed to send data to backend.
In the end I decided that when there are edit, file input not need to be required, because object get information about ealier choosen file, and you can change it, but can't remove.

Pass value between express routes

I have an html form in one of my views. One value in that form is a username. I gave that input an id.
<input name="username" class="form-control" id="username" placeholder="Username">
When the form is submitted, I redirect to a new view.
res.redirect('/nextView');
nextView has a javascript file being served to it from my public folder. In that javascript file, I am trying to access the username value like this:
$('#username').val()
This is not working. I think it's because now that I am on nextView, the id 'username' does not exist.
How can I persist this value from one view to the next?
You can redirect to a URL with a query parameter attached or save a cookie value.
To attach a query parameter:
res.redirect('/nextView?userName=' + username)
To read from a query parameter in the browser use a queryParam parser. Example

Sailsjs Waterlock - Set up multiple auth methods

I have been learning how to use SailsJS most effectively, which includes using authentication. After the nightmare that sails-auth gave me, I decided to use Waterlock.
I have a default setup with Waterlock. I am trying to use multiple auth strategies (waterlock-local-auth + waterlock-google-auth).
Whenever I POST credentials to the register page, I am presented with
HTTP 400: you must specify a type parameter.
After reading the code, I notice I must submit an authentication type string with my form submit. So I add <input type="hidden" name="type" value="waterlock-local-auth"/> to the form. However, now I am presented with this:
HTTP 400: unknown/invalid authentication type
Why?
The proper way to encode the type string in the form data this way:
Your auth package name is waterlock-x-auth
The value on the input tag should be x
The input tag (if using local, for example) would look like this:
<input type="hidden" name="type" value="local"/>

Can file names be changed on uploading with cffile?

I am currently trying to create a page where bands can upload their own logos onto the site for use where it is needed. Currently, I have created something which allows a user to upload/delete a logo to the allocated directory. But what I want to do is rather than create a band_logo field, have it so the band logo file name becomes the band's id in the database. With this being unique it means I don't have the long-winded process of creating a field to save their logo name. I know there is a cffile action="rename" option but that is a more long-winded process of doing things.
Yes, if you provide the file name in the destination it will rename the file on upload.
<cffile action="upload" destination="/path/to/some/directory/#session.bandName#.jpg" ... />
See Renaming Files As They Are Uploaded (how CFFILE actually works)
BTW, searching google for "name file on cffile upload" found that article...
However, you still may want to use
<cffile action = "upload" ...>
then
<cffile action = "rename" ...>
Because unless you snag the file extension on the client side and pass it on to the server, hard coding the file extension could cause problems if they don't upload a .jpg or whatever extension you designate. It isn't that much code or overhead and it's safer.
<cfif #ServerFileExt# EQ 'jpg'>
<cffile action="upload" destination="/path/to/some/directory/#session.bandName#.jpg" />
<cffile action="rename"
source="path/to/some/directory/#session.bandName#.jpg"
destination="path/to/some/directory/#getData.bandsID#.jpg">
<cfelse>
<cflocation addtoken="no" url="back to form upload page">
</cfif>

Saving file to server in ColdFusion

After doing some research I feel this should work, however it is not saving the file to my Images directory.
<cfform name="uploadImgForm" method="post" action="#CGI.PATH_INFO#?#CGI.QUERY_STRING#" enctype="multipart/form-data">
<input name="txtImg" type="file" />
<input name="btnSubmit" type="submit" />
</cfform>
<cfif isDefined("Form.txtImg")>
<cffile action="upload"
fileField = "txtImg"
destination="/Images"
accept="image/jpeg"
nameconflict="makeunique">
</cfif>
I plan on doing some validation, but I would like to get this simple example working first.
I came across this later which is helpful when trying to rename a file before upload:
Adobe link
The destination has to be a full path, otherwise it gets sent to a directory relative to the temp directory of ColdFusion.
Try this:
<cfset destination = expandPath("Images") />
<cffile action="upload"
fileField = "txtImg"
destination="#destination#"
accept="image/jpeg"
nameconflict="makeunique">
Are there any error messages at all? Or, after posting, do you just get the form again?
Firstly, does the /Images directory exist under the default CF temp directory?
Secondly, try getting rid of the "accept" argument to the CFFILE, just in case your browser's sending an odd MIME type.