Adding custom data based attributes based on Response object - dropzone.js

Halo ! I'm trying to implement dropzonejs in a very specific way. Actually I follow the standard implementation described on the official page. Everything works perfectly.
But I'm willing to attach the server's generated URI for each uploaded file directly when uploaded : when uploading it's creating a database entry with some stuff like a page uri with title etc. This mean that the server would return as a response the id of the database saved file in order to attach the href attribute with its value to the the element in front.
This is quite ok to do this when only one file is uploaded, but it becomes trickier when bulk uploading.
So maybe I didn't understand the documentation well (and I'm quite sure I didn't), but is there any way to add custom data-dz-like attributes based on my server's response ? I'd like something like data-dz-url where the url points to a database entity (not the file itself).
Or if not if there is an "easy way" to handle this.
Thanks a lot

Here is the answer :
myDropzone.on('success', (file, response) => {
file.previewElement.href = "/admin/media/"+response.id+"/show/"
})
file is reference to the current uploaded element. It's possible to extend it's html attributes through previewElement. Setting the data-type attribute in the template before, then assigning it the right value works aswell.
Hope this will help some.

Related

Kademi - allow front end user to delete a file they have uploaded

I am trying to allow front end user to delete a file they have uploaded.
#docs() tells me that $page.lead.files has a method called .remove() that accepts either an Int or an Object.
I keep getting a response of "false" when using this method. I am trying to pass and ID or Object of a file within $page.lead.files object.
Debugging...
User: https://spinsurance.admin.kademi.com.au/manageUsers/116783806/#summary-tab
Page: https://crm.spinsurance.co.nz/leads/148615383/
Source: https://spinsurance.admin.kademi.com.au/repositories/spcrm/version1/theme/apps/leadman/components/texteditor?fileName=leadDetailTabContentComponent.html
Under section on page called: Uploaded Files.
Click big red Delete button. (I don't mind if this file gets deleted)
Thanks for your help in advance.
The Lead.files property is a persisted list. Its not a good idea to try to modify the database using that approach.
Note that lead files are exposed as http addressable resources, which support the http DELETE method
So the simplest approach is to delete from the browser using ajax
Eg
DELETE /leads/123/myfile.pdf

How to retrieve an image from a database using imageid in the controller

Saving the image in a web directory and storing the URL in the database using this approach, I stored the image URL in the database. Based on that image id (I need to pass this image id to the controller from an Ajax call). I need to retrieve the image.
I got the image id using a jQuery template, so I have passed that image id to the controller. What should I write in the controller, filepathresult or fileresult? Or is there another approach?
OK, you're a bit confused.
You have the actual image file, file.jpg and you have the physical path to the file, D:\some\path\to\file.jpg.
You have the URL path to the file and a surrogate identity (your id).
id: 1337 (some random number)
URL: ????
First question:
You say you're storing the URL. Is it really the complete URL? Is it just a partial path to the image? Is the path from the root of the website or the root of the application? Is it just a partial physical path?
Second question:
What are you actually trying to do?
Do you just want to get the full path to the image? Why do you need Ajax to do this, if you already have the id? You might want to rethink how you're storing the images if any performance needs to come out of this.
Once an image gets a new identity, it often makes sense to use that new identity everywhere; you might ought to consider copy/rename the file for the new identity after it's uploaded (and possibly save the old filename for record keeping purposes). If you need to keep the file names (more or less) as-is, however, it'd be better to provide the ability to grab the URLs for a whole set of ids rather than to individually make an Ajax request id-by-id.
If you request a resource (AKA navigate to a URL) that has a physical file, IIS is going to serve it directly (that is, if you ask for www.mysite.com/Images/Image3.jpg IIS is going to serve it directly). I really don't understand exactly what you are doing, but if you mean that you get the associated URL for an image using an Ajax call to an MVC controller with the id of the image, you could do several things.
You could simply return the URL and use JavaScript code to create an image tag with that URL and inserting it in the DOM.
You could return a view like <img src="{yoururl}" /> and insert it in the DOM using JavaScript.
You could store the images on the database directly and use the File method to return the image bits indicating the correct MIME type.

Joomla File Handling - Variable name not passed

I made a component with a "file" field type, but the content of that single field are not passed at all, I was under the impression it should save the file name as text at least, if I change the field type to "text" the name saves so I know everything else is functioning. All the other fields are being passed. What am I doing wrong?
File handling aside, I just want it to save the name.
A detailed explanation would be appreciated, or even better, can I get someone who knows what he's doing re-write this component using MVC so I can compare.
Thanks
Can't really help with what you have so far as you haven't provided any code, however our website have recently made a small simple component for Joomla 2.5 for file uploading using the SWFUpload framework, should you want to use it.
http://joomjunk.co.uk/products/component-home/swfupload.html

Posting a collection to MVC3 from Plupload

I've got a documents upload page in an MVC3 application that lets the user upload documents to be stored in a database and associated with a parent entity in the database. There are also some permissions that the user can customize to stipulate who can access the document.
I've implemented my document upload functionality with Plupload, The behavior that it's working with is that essentially it will take a queue of files, and upload them for me to a specific action dedicated to recieving this information, and when they are posted each file is given a unique name (something like p16kearti61rf31qb61fogjm2127i3.jpg for example.)
Once all of the files have been uploaded in plupload, the parent form is submitted with the information about the files plupload just uploaded as well as some other data for the documents like the Primary Key of the object they are to be associated with, and the groups that have been checked off for it's permissions aspect. Now this works fine except that I can't find a strongly typed object structure that MVC will bind my data to so that I can work with the posted back data. Here's an idea of what is in my Request.Form collection, what I'm looking for is some insight on how to best capture this information in my action. I have complete control over the naming of the controls for the document permissions, but the plupload controls are built in and I'd don't know if I can change them.
__RequestVerificationToken: "...XDsBA5oZA9Ku2oPPdyyi2J+DbvoKRY9HJ2...etc"
ownerId: "CCEE2ADF-633D-4D55-90EE-2829D352BEEB"
uploader_0_tmpname: "p16kearti61rf31qb61fogjm2127i3.jpg"
uploader_0_name: "picture1.jpg"
uploader_0_status: "done"
uploader_1_tmpname: "p16kearti61kqu8tsmja67911v44.jpg"
uploader_1_name: "picture2.jpg"
uploader_1_status: "done"
uploader_2_tmpname: "p16kebp785gci1e291i543cc1c8k4.jpg"
uploader_2_name: "picture3.jpg"
uploader_2_status: "done"
uploader_count: "3"
documentGroups[B8C97C5C-B1B8-43C2-89F1-B1DF353AF677]: "false"
documentGroups[A2C8331C-7068-4611-82BF-6F0C61C8BA7D]: "false"
documentGroups[6DCBF4A8-B863-49E6-AAE9-2A0E372FF622]: "true"
documentGroups[05C04E05-D7A8-45D6-8138-2FA36F0A5922]: "false"
documentGroups[3E2F2B1B-FAAA-420A-B9A1-F223ADF66AF0]: "true"
Any suggestions on how to write my action method? I was hoping for something like this but I can't get it to work.
public ActionResult Upload(Guid ownerId, IList<PluploadFile> uploader, IList<bool> documentGroups)
Just in case someone else was looking for an update on this (and since I got no response to my question what-so-ever), I ended up splitting my post into two; one handled by plUpload which I use to save the file(s) to a temp folder using the unique names pased in to the Action from plUpload (such as p16kearti61rf31qb61fogjm2127i3.jpg), and the other when I post the wrapping form which holds the information I need and the unique names plupload has as well as some fields indicating the status result of the original upload. The problem is that because it's two posts I now have to look at maintaining the contents of my temp folder in case the user uploads documents but doesn't submit the wrapping form. Not the solution I wanted but I can't an alternative working as expected.

Automating filling Forms

Renting houses can be nasty so I need to automate it. Please, have a look at here. If you make a mistake, all of your changes are gone. I tried to insert the values in the url like:
https://www.hoas.fi/web/hak_inet.nsf/WebHakemus?OpenForm&02.07?PersonFirstName=Alex?PersonLastName=Smith
but it does not work. What is the problem?
Firstly, your query string is incorrect. It should be:
https://www.hoas.fi/web/hak_inet.nsf/WebHakemus?OpenForm&02.07&PersonFirstName=Alex&PersonLastName=Smith
Secondly, in order to pre-populate the page with the results of the query string, the developer of the page would have had to added logic to extract the query string values and pre-populate the page with those values. In this case, it does not appear that they have done that.
You could try saving the page locally as HTML. Then you could modify the HTML to include your default values. You would also need to update any relative paths to point to the server as a full URL. Then you could open the page on your machine and hopefully post to the server. This assumes that they are not injecting any session or other temporary information in the page that they validate.

Resources