Need to download files in zip format

Hi,

I have list of files on UI which i want to download in zip folder.

What is the way out to implement this approach.

Kindly share me any code or any approach on this ?

  Discussion posts and replies are publicly visible

Parents
  • How you are passing doc details to PM.

    I mean below details you are passing from Interface or plugging at PM level.

    I think so Base Doc/Save In folder/Document Path is optional here rest is mandatory. 

    Why do we need to pass path here if required as i just want to bundle out all my files n zip them in one folder. i don't want to save anywhere.

    Kindly share some inputs on that.

  • Why do we need this Documents Path as we are storing document id in DB and getting back by using some function from Appian portal. Then which path we need to refer here.

  • 0
    Certified Lead Developer
    in reply to sauravk
    Why do we need this Documents Path

    The "Document Paths" input will determine the path and filename for the matching document from the "Documents to Add" array within the generated ZIP file only.  Therefore if you only want the documents to be at the "root level" of the zip file (the most common way), you would simply pass an array of the filenames.  This needs to include the file extension, i.e. {"file1.docx", "file2.docx"}, not {"file1", "file2"}.

    And for further clarification, if you wanted the files to be in a folder off the root of the zip file, let's say a top level folder called "Documents", you would pass this array: {"Documents\file1.docx", "Documents\file2.docx"}

  • 0
    Certified Lead Developer
    in reply to sauravk
    I think so Base Doc/Save In folder/Document Path is optional here

    Per my best understanding (and supported by myself using it successfully in the past):

    If "Create New Document" is set to TRUE, then you must provide "New Document Name" and "Save In Folder".

    If "Create New Document" is set to FALSE, then "Existing Document" is required - the files will be added to the "Base Document" zip file (if provided) and the changed file will become a new version on the same file ID.

  • Thanks Mike for your inputs. Now I have followed your approach but having facing some exception. Sharing code snippet what I have done so far.

    secondaryButtons: a!buttonWidget(
                      label: "Download",
                      icon: "download",
                      saveInto: a!startProcess(
                        processModel: cons!DOC_ZIP_PROCESS,
                        processParameters: {
                          documents:
                           difference(a!forEach(
                    items: index(
                      local!dataSet.data,
                      "docId",
                      null
                    ),
                    expression: if(
                      or(
                        isnull(
                          fv!item
                        ),
                        not(
                          isobjectexists(
                            "Document",
                            tointeger(
                              fv!item
                            )
                          )
                        )
                      ),
                      "",
                      document(
                        tointeger(
                          fv!item
                        ),
                        "name"
                      )
                    )
                  ),""),
                          documentPath:
                           difference(a!forEach(
                    items: index(
                      local!dataSet.data,
                      "docId",
                      null
                    ),
                    expression: if(
                      or(
                        isnull(
                          fv!item
                        ),
                        not(
                          isobjectexists(
                            "Document",
                            tointeger(
                              fv!item
                            )
                          )
                        )
                      ),
                      "",
                      document(
                        tointeger(
                          fv!item
                        ),
                        "name"
                      )
                    )
                  ),""),
                          zipName: tostring(
                            "Test Doc"
                          ) & "File_.zip",
                        }
    
                    )

    Base Document - Blank

    Create New Document : True

    New Document Name-=pv!zipName

    New Document Desc : Blank

    Save In Folder - Temporary Documents(Selected folder via search browser window)

    Existing document- Blank

    Document to Add- =pv!documents

    Documents Path- =pv!documentPath

    In Document to Add and Documents Path I am passing same content . I am passing list of documents name as you suggested. But I am getting below error now.

    Where I am missing. Now in documents,documentPath in both variable there is no null data after using difference() function. I am not understanding where this null coming now.

  • I have tried to change document n documentPath variable but now new error is poping up.

      documents:12754,

     documentPath:document(12754, "name"),

    I am not sure what i am passing in document n documentPath is correct or not. I feel so error is around this variable only.

    And then tried with below parameters also.

     document:-
     reject(fn!isnull,
                             a!forEach(
                    items: index(
                      local!dataset.data,
                      "docId",
                      null
                    ),
                    expression: if(
                      or(
                        isnull(
                          fv!item
                        ),
                        not(
                          isobjectexists(
                            "Document",
                            tointeger(
                              fv!item
                            )
                          )
                        )
                      ),
                      null,
                      document(
                        tointeger(
                          fv!item
                        ),
                        "name"
                      )
                    )
                  )),
    documentPath:-			  
    reject(fn!isnull, difference(a!forEach(
                    items: index(
                      local!datasubset.data,
                      "docId",
                      null
                    ),
                    expression: if(
                      or(
                        isnull(
                          fv!item
                        ),
                        not(
                          isobjectexists(
                            "Document",
                            tointeger(
                              fv!item
                            )
                          )
                        )
                      ),
                      "",
                      document(
                        tointeger(
                          fv!item
                        ),
                        "name"
                      )
                    )
                  ),"")),

    But getting below error.

  • 0
    Certified Lead Developer
    in reply to sauravk

    I'm not sure if this is what's causing your error, but you should be aware that the smart service expects you to provide the full document name as I mentioned before, which is the name + extension (so far your code just passes the name).  For example,

    document(fv!item, "name") & "." & "document(fv!item, "extension")

    It might still work without the extensions, but your resulting zip file will end up with files without extensions which you probably don't want.

    Other than this, all I can suggest is monitor a running instance and make sure your PVs have populated correctly - most importantly, pv!documents (should be either an array of document or an array of integer, the node will correctly typecast what it needs from either of these), and pv!documentPath (this needs to also be an array of course, at the very least containing the full name of each document in the array).

  • Hi Mike,

    As i have shared my code in that i passing documents(array of doc id) and now i changed documentpath (array of name). But still java.lang.ArrayIndexOutOfBoundsException: 0

    But if i change documents  value to same as documentpath then i get java.lang.NullPointerException: Null Arguments are Invalid

    It means documents(array of doc id) is correct format i feel so as per exception.

    Why this ArrayIndexOutOfBoundsException this coming ?

  • 0
    Certified Lead Developer
    in reply to sauravk

    I'm not sure what the source of that error is - the only thing I can suggest is to verify that your inputs are being entered correctly and correctly populated within the process instance.  Can you post a screenshot of the values of "documents" and "documentPath" from within a process instance?  It sounds almost as if one of the required values for the node is actually set as something invalid within the process instance (such as 0, or an empty set).

  • documents:-1245;1232;4567

    documentPath:-test-sample.csv.2014-06-13; test-sample.csv.2014-06-25; test-sample.csv.2014-06-13;

    Exact these values are going to PM.

     

Reply Children