Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: How to write any file type into a blob with javascript

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    335

    How to write any file type into a blob with javascript

    WebApp, canvas section, Image, filling other file types into the blob:

    In the App Builder you can write pictures into an image field using the existing dialog.
    I also want to store other file types in the blob.

    In a prg file it is no problem to write any file type into a blob field (e.g. by VFP and getfile and objectwrite)

    Is there an easy way in JavaScript to do this using a property?

    Thanks Georg

  2. #2
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,930
    Hi Georg,

    Would an Attachments Section work for what you want to do?

    Regards,

    Yvonne

  3. #3
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    335
    I don't really want to have an extra attachment section, because if there are too few data records, an image file, PDF file or something else will be attached. The dialog for the image could actually be expanded for other file types, because everything goes into the same blob.

    What's about Carneval ? ;-)
    Georg

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,385
    Blog Entries
    22
    Hi Georg

    https://www.lianja.com/doc/index.php...ods#uploadFile

    Write your own upload_file.rsp (copied from upload_image.rsp in the wwwroot directory).
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  5. #5
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    335
    Thank you, Barry, for the detailed work! I only need "evaluate" from it.

    var err = Lianja.evaluate("save2blob('" + par1 + "','" + par2 + "')" ) ;
    par1 = filename
    par2 = my autoinc identifier
    and this is save2blob.prg

    parameter filename, identnr
    identnr = val(identnr)
    save datasession
    if !database() = "mydatabase"
    open database mydatabase
    endif
    if !used("mytable")
    use mytable in 0
    endif
    select mytable
    set order to IDENT_SEARCH
    err = seek(identnr)
    if !err
    messagebox("No such index")
    else
    err = objectread(filename, mytable.blob)
    messagebox(filename + "write to blob successful")
    if !err
    messagebox(filename + "write to blob not successful")
    endif
    endif
    restore datasession
    return err
    Following other problems:
    1) How do I say my js input program that something has been changed when I otherwise I don't change anything in the input form?
    2) I see the output of jpg files in the image field, but how can I download other files of other types?

    Thank you
    Georg

  6. #6
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,930
    Hi Georg,

    1) Can you explain further?
    2) Create a download link as you did here.

    Regards,

    Yvonne

  7. #7
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    335
    Hello Yvonne!

    Regarding 1)
    The phenomenon (Canvas section):
    a) I select text using a combobox and use a click function to write the text into a text box connected to a field in a data table. This change isn't saved with the "Save Changes" button, but only if I manually add something to the text box, e.g., add a space.
    b) In my opinion, something similar happens when I write something to a blob using a prg file (see above). It isn't permanently saved. I'm looking for a way to indicate to the dataset that something has been changed so that it is saved.

    Sometimes I can achieve this by manually changing something else in a text box, but not always.

    Additionally, reading the blob often results in a *.pytc file instead of a *.pdf, *.mp3, etc. file (this doesn't happen when entering a *.jpg in the blob, as it is displayed in the image field.

    Regarding 2)
    Do you think I should upload the entire app?
    The package has ca 20MB.
    Where should I load the package to (if I'm interested)?
    There's only private data in the database.

    Thanks very much
    Georg
    Last edited by gcjm; 2025-03-13 at 13:17.

  8. #8
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,930
    Hi Georg,

    1a) The text box is not marked as 'dirty' if you are programmatically changing the text. Change the data in the cursor too, e.g.

    Code:
    ca = Lianja.getCursor('name-of-table');
    ca.setData('name-of-field','new-value');
    1b) I suspect the data is saved, but then overwritten when you save the record you are editing. Can you access the upload outside of an edit of the full record?

    What does objecttype() return when you upload the file?

    2) Did you follow the link I included to the earlier thread where we discussed downloading files via a download link in a .rsp file in a webview (could be a section/gadget/Canvas section advanced control)?

    Regards,

    Yvonne

  9. #9
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    335
    Hello Yvonne,

    today to 1a) only:

    function page1_section1_field19_click()
    { var oItem = Lianja.getElementByID("page1.section1.field18");
    var auswahl = oItem.text; // selected text of the combobox = > ok

    var cursor = Lianja.getCursor("ereignis");
    cursor.setData("betreff",auswahl); // ok in Desk but not in WebApp
    // cursor.refresh(); // it looks like I need a refresh but it doesn't work
    };
    What could be wrong?
    Thanks an bye
    Georg

  10. #10
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,930
    Hi Georg,

    If you do not have 'Enable when editing' set on the Canvas section - where you click edit and save/cancel to edit the data - include an update call after the cursor.setData(...):

    Code:
    cursor.update()
    Regards,

    Yvonne

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us