any pointers on how I would go about receiving/upl...
# cfml-general
m
any pointers on how I would go about receiving/uploading a multipart/formdata file (from axios) to a coldbox api?
s
I don't think there's anything special about doing this with Coldbox. cffile to process the form field and do whatever you need to do with it
Coldbox doesn't really care that the file came from a front end with axios vs. any other source, it just sees a form POST
e
I would avoid the CFFILE tag and instead, use standard form processing as its best practice plus you can have fine-grained control of what you do with those files.
m
huh guess I was overthinking everything since it was new to me but cffile seemed to work well. what do you mean by standard form processing?
but now i have i a new problem we need to rename the files so we know the user there associated with, i could do cffile upload then cffile rename, but I would prefer a way to get the file name from the header field and append the user info to the file name
e
you can do that with the session scope, as I would hope you are forcing your user to login somehow. Then you can run a sanitation against the file with a processing file, after you upload the file in the form action put it to a coldfusion page, in that page you can do all kinds of sanitation, check if it came from a secure user, so on and so forth. As part of the check for "who uploaded the file" which should be part of the session (You are hopefully asking people to login?) you can set whatever you like to the filename, so if you want session "Bob" to upload files, you can do a cffile =action rename sessionID (BOB)-yourfile.enforced_fileEXT
m
I could be wrong but I think you have some wrong assumptions so ill just dump all the info I have. this is a vue app that's using a coldbox api. users are verified by JWT's for all api calls. the file itself is being passed as a multipart/form-data via axios. this cffile works fine and will upload the file with the original name to the proper directory. however we want something like this with the user id prepended to the original file name. is there a solid way to do this with with out cffile upload and cffile rename
e
Then pull the userdata from JWT, or again the scope, or database, or anything else you like. After you do that, you would just set that varable as part of the file. I suggest first you upload the file and run sanitation checks and then you rename the file and move it to where you need it. So you have result.filewassaved you could then add result.FileIsProcessed= session.userid.resultfilewassaved
dump your scope, find what the userid is, if you are even passing that from vue.js to your processing page.
<cfoutput>
<TABLE>
<TR>
<TH>Variable Name</TH>
<TH>Value</TH>
</TR>
<!--- loop over the Form structure and output all
of the variable names and their associated
values --->
<CFLOOP COLLECTION="#Form#" ITEM="VarName">
<TR>
<TD>#VarName#</TD>
<TD>#Form[VarName]#</TD>
</TR>
</CFLOOP>
</TABLE>
</cfoutput>
m
the output of this is
sorry uploaded the wrong output
e
Your output looks like its only producing a UUID. Without knowing the code of your vue file, my guess is your UUID maybe session but not the userid. you could either query the uuid against the sessionid and come up with the username to prepend the file or you could adjust your vue file to include the username.
a
He is using jwt and not session. So the session variables won't work as you expect them to be.Decrypt your access token and check if user id is being saved in the access token or not. If it's being saved then you can easily access it. Instead if you are only storing the ID then fetch the username from the database using the user id retrieved from the access token.