


srikanthr646926
srikanthr646926
02-05-2018
Hello,
I am trying to Create WebApp for Support team, where we handle new requests. I am trying to add Upload File by linking fileRes to Custom table I created, Unfortunately it is showing error when click the Storage option.Vipul Raghav marcel.gent.86 Can you guys help me on this.
Thanks
Srikanth
MarcelSzimonisz
MVP
MarcelSzimonisz
MVP
03-05-2018
Hello srikanthr81596981,
why not use functionality which is already there?
1.
choose context variable (eg ctx.vars.file) to save your file from form
2-3 step:
See any file res xml to know what to save
ctx.vars.file -->has e.g @md5, @originalName.
//create all fields you want to save
//create xml
var fileResXml = <fileRes contentType={contentType}
internalName={intName} label={originalName} md5={md5Var}
name={destFileName} originalName={originalName}
xtkschema="xtk:fileRes"><folder id={folderId}/></fileRes>;
//create file res obj
var fileResObj = xtk.fileRes.create(fileResXml);
//publish
fileResobj.PublishIfNeeded();
//save it to db
fileResobj.save();
var fileResId = *query resource id by unique internal name*;
///save resource id to linked table?
fileResobj.save();
fileRfileResobj.save();esobj.save();
Hope this helps,
Marcel
srikanthr646926
srikanthr646926
03-05-2018
Hi Marcel,
Thanks for the reply . I am
actually new to creating web Apps but I did not find the web app form with file upload template. Can you please let me know where exactly to find it?
MarcelSzimonisz
MVP
MarcelSzimonisz
MVP
03-05-2018
Hello srikanthr64692681,
In web app edit tab choose Page activity
In page Advanced controls -> File
Or you can change any input to file type input in "Selection controls"
Set up storage by choosing your context variable (you can create them here aswell)
After page JS activity has to be placed with following-ish code
The variable you set for the image field will contain following attributes after submit
<ctx>
<vars>
<fileImg id="0" md5="af859bcc5957fd1a60f7387d07c672ff" originalName="C:\Users\USER\Pictures\3RzNQc8Ia07A_GjjY49XOt.jpg"/>
</vars>
</ctx>
so that means in JS you can distinguish from it md5 string, contentType ...
ctx.vars.fileImg -->has attributes e.g @md5, @originalName if you want to see all of them
//create all fields you want to save
//create xml
var fileResXml = <fileRes contentType={contentType}
internalName={intName} label={originalName} md5={md5Var}
name={destFileName} originalName={originalName}
xtkschema="xtk:fileRes"><folder id={folderId}/></fileRes>;
//create file res obj
var fileResObj = xtk.fileRes.create(fileResXml);
//publish
fileResobj.PublishIfNeeded();
//save it to db
fileResobj.save();
var fileResId = *query resource id by unique internal name*;
///save resource id to linked table?
fileResobj.save();
Marcel
srikanthr646926
srikanthr646926
03-05-2018
Awesome Thanks marcel. I will implement and let you know.
MarcelSzimonisz
MVP
MarcelSzimonisz
MVP
03-05-2018
Hello again,
one more thing
Maybe this will be needed
fileRes.PostUpload ();
As well as setting storageType="5" to that fileRes xml --> 5 is default although i do not know what that means
Let me know
Marcel
srikanthr646926
srikanthr646926
03-05-2018
Hi Marcel , I am able to save the file and but it is not uploaded on the server(I need to manually go and upload), Like you have mentioned it is something to do with below method
fileResObj.PostUpload(); Post Upload takes XML params
do I need to define like
fileResObj.PostUpload(<params name={orignialName} md5={md5var} />)
And also How do I to link to my custom Table?
MarcelSzimonisz
MVP
MarcelSzimonisz
MVP
03-05-2018
I think not as fileResObj already has this in it. But you need to try that
srikanthr646926
srikanthr646926
03-05-2018
At this time it is just creating an entry not upload the actual file on to server.
srikanthr646926
srikanthr646926
03-05-2018
Hi Marcel,
Thanks for all your help, I am not able to upload it on the Server. There must be something I am missing my Form is creating an entry with definied variable in the script but it is not uploading the file to server. I am excepting something like this