Container file name reuse

A place for users and developers of the Xataface to discuss and receive support.

Container file name reuse

Postby linux123 » Sat Jan 23, 2010 3:08 pm

Hi Steve,

my application is using containers for several fields from PDF files to images, using the file widget type so only the file name is saved in the database.
Many times, the same files or file names are needed for many different fields, e.g. a lot of products share the same pictures or documents.
In the current implementation, creating a new record results in redundant copies of the same content, like product.jpg, product-1.jpg, product-2.jpg etc. each time I save "product.jpg".

How can I avoid this and use the same file name multiple times, pointing to the same object in the datastore?
I.e. if an already existing file is selected, the name is taken without copying anything, thus avoiding redundancies.

Thanks!
Bernd
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm

Re: Container file name reuse

Postby shannah » Mon Jan 25, 2010 10:43 am

Ah.... this is a bit of a sticky issue. I took the safest route when I implemented file uploading to avoid the possibility of accidentally deleting files unintentionally. So you are saying that if, in tableA you upload a file named picture.jpg, but there is already a file by that name stored in a record in tableB, then it overwrite tableB's picture.jpg with the new one and have both the record from tableB and from tableA reference the same picture.jpg file?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Container file name reuse

Postby linux123 » Mon Jan 25, 2010 1:38 pm

shannah wrote:... in tableA you upload a file named picture.jpg, but there is already a file by that name stored in a record in tableB, then it overwrite tableB's picture.jpg with the new one and have both the record from tableB and from tableA reference the same picture.jpg file?


Not exactly ... I am trying to let multiple records use the same file "picA.jpg" in the "repository" (the repository is the place where the container contents are stored, i.e. the savepath).

If a user tries to import a new file, that file is always copied to the repository (it would be convenient if there would be a warning about an existing file name popping up, but copying picA.jpg to picA-1.jpg would be ok for now).
But if an already existing file inside the repository is chosen on purpose, then nothing is copied but only the filename "picA.jpg" is entered into another record. So already existing content in the repository could be used multiple times.

If picA.jpg is removed later but may be referred to from different records, maybe nothing should be deleted to avoid cases where different fields point to the same file - this is certainly something that must be considered.

Maybe this is all the wrong idea and I should implement it differently?
The more I think about this, it seems clear that the file repository and the fields from my user form that contain the link to that file are two very different things/objects.
So probably what I really want is a file repository (e.g. for managing images or PDF files) and the possibility to just choose files from this repository for certain field content in my application. The first would be easy, the second I have no clue yet - how can I use a file-widget with a fixed "savepath" that will only store a filename/URL but not the contents? I tried without "Type=container" but it was not working as I expected ;-)


Bernd
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm

Re: Container file name reuse

Postby shannah » Mon Jan 25, 2010 2:02 pm

One possible solution is as follows:

1. Create a valuelist with all of the files in your repository. You would create the valuelist in the delegate class to you could generate a dynamic listing of the files.

2. Still use the file upload field for new uploads (i.e. the container field).

3. Add a transient field to allow users to select an existing file from your repository. This field would be a select list that uses your valuelist (from #1 above) as its vocabulary. You could even use some slick javascript to preview the image when you select a file from the select list.

4. In the beforeSave() handler, you can set the value of your container field with the selected file in your transient field (if one was selected).

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 18 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved