Hi Massimo,

I am using upload attachments. I have Create and Edit pages with number of 
fields. Upload is one of the fields. Now in create page, it was pretty 
straight forward using, Upload field in model. 

Table name is service_attachments
Field('attachment','upload',uploadfolder=os.path.join(request.folder, 
'attachments')) (Model)

if form.vars.attachment:
                form.vars.attachment_name = request.vars.attachment.filename

>       id = 
> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>  
> .(Controller) 

And this works great.It inserts the record into the table and also saves 
the attachment into the folder as -  
service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.jpg
 
Now for edit functionality page, I want users to be able to add more 
images. Just calling the form.custom.widget.attachment again is not serving 
the purpose. So I tried doing, manual upload for this particular page. Eg, 

<input class="upload" id="service_attachments_attachment" name="attachment" 
type="file" /> (view)

I recreated this HTML statement with taking reference of what the Create 
upload field creates in HTML.. 

In Controller,

> if request.vars.attachment != '':
>                 form.vars.attachment = request.vars.attachment.file
>                 filename = request.vars.attachment.filename
>                 form.vars.attachment_name = filename
>                 id = 
> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>
Just Assigning this manual field to the already existing upload field. 

This saves the file, the same way as upload field does. It does save the 
file in the folder specified and also inserts the record in the 
service_attachments table.But, it saves the extension of that field as 
.txt, regardless of what the file type is. It saves the file as .txt in the 
folder and the db record.
Let me now if this is giving you the clear picture. 

Arti 


On Thursday, December 20, 2012 7:10:47 AM UTC-8, Massimo Di Pierro wrote:
>
> Can you explain what you are trying to accomplish and what your models 
> are? I do not understand from the code.
>
> On Tuesday, 18 December 2012 13:51:12 UTC-6, ArNew wrote:
>>
>> Hi Everyone,
>>
>> I need help urgently.
>>
>> In my application, I am have included upload fields in Create and edit 
>> page. Through create page, it was very straight forward with:
>> <td>{{=form.custom.widget.attachment}}</td> (View)
>> Field('attachment','upload',uploadfolder=os.path.join(request.folder, 
>> 'attachments')) (DAL). 
>> if form.vars.attachment:
>>                 form.vars.attachment_name = 
>> request.vars.attachment.filename
>>                 id = 
>> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>>  
>> .(Controller) And this works great.
>>
>> That with Edit page is not the same, as it is not about editing the 
>> current image, but uploading more attachments. So I tried doing something 
>> like this:
>>
>> <input class="upload" id="service_attachments_attachment" 
>> name="attachment" type="file" /> (view)
>> if request.vars.attachment != '':
>>                 form.vars.attachment = request.vars.attachment.file
>>                 filename = request.vars.attachment.filename
>>                 form.vars.attachment_name = filename
>>                 id = 
>> thisdb.service_attachments.insert(**thisdb.service_attachments._filter_fields(form.vars))
>> This follows the very similar procedure of saving the encrypted version 
>> of attachment name in the attachment field, but it changes the extension to 
>> .txt for all the attachments. It saves the attachment as 
>> service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.txt 
>> where as the orginal attachment is photo.JPG. So ideall it should save it 
>> as  service_attachments.attachment.b19d4ef38978e8e6.746d707437756c626f.JPG. 
>>
>> Can anyone please help me with this?
>>
>>
>>
>>
>>
>>

-- 



Reply via email to