Results 1 to 4 of 4

Thread: FileField is empty after submit.

  1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    8
    Vote Rating
    0
      0  

    Default FileField is empty after submit.

    When I perform a submit, I don't see the fileField properties in the handler. Here is my JS code:


    { xtype: 'container', margin: '5 5 5 5', border: false, frame: false, layout: { type: 'hbox' }, items: [ { xtype: 'form', fileCount: 1, id: 'adpAttachmentFormid', border: false, api: {submit: 'iConnect.Attachments1.saveFile'}, items: [ { xtype: 'filefield', emptyText: 'Click Browse button to add a file', buttonText: 'Browse', width: 300, id: 'fileid', disabledCls: 'disabledControl', listeners: { change: function (file, value) { if (file.value != file.emptyText && file.value != "") { var grid = file.up("form").down("grid"); var store = file.up("form").down("grid").getStore(); //get the store from the grid on the form var form = Ext.ComponentQuery.query('form[id="adpAttachmentFormid"]')[0]; form.submit(); store.add({ objId: store.count() + 1, fileName: file.value, fileLink: file.value, version: 1, additionalInformation: "", attachedBy: "", isForInternalUseOnly: 0 }); grid.show(); file.reset(); } } } }, { id: 'uxadpfileuploadgridid', xtype: 'uxadpfileuploadgrid', hidden: true }] }]And this is the handler code:
    [DirectMethodForm] public JObject saveFile(HttpRequest request) { try { for (int i = 0; i < request.Files.Count; i++) { if (request.Files.Count > 0) { HttpPostedFile file = request.Files[i]; if (file.ContentLength > 0) { fileName = Path.GetFileName(file.FileName); BinaryReader b = new BinaryReader(file.InputStream); byte[] binData = b.ReadBytes(file.ContentLength); fileSystemObj.CreateDirectory(temporaryFolderPath); fileSystemObj.ByteArrayToFile(temporaryFolderPath + "\\" + fileName, binData); } } } retMessage = " was successfully uploaded."; } catch (Exception ex) { ADPDS.CustomExceptionHandler.ExceptionHandler.HandleException(ex, "DBLog"); return new JObject( new JProperty("success", false), new JProperty("file", fileName), new JProperty("message", "file failed to be uploaded.")); } return new JObject( new JProperty("success", true), new JProperty("file", fileName), new JProperty("message", "file was successfully uploaded.")); } But file variable above does not contain the properties such as file name and contents.ThanksAlex

  2. #2
    Sencha User
    Join Date
    Aug 2012
    Posts
    8
    Vote Rating
    0
      0  

    Default Cleaner code

    Code:
    {
        xtype: 'container',
        margin: '5 5 5 5',
        border: false,
        frame: false,
        layout: {
            type: 'hbox'
        },
        items: [
        {
            xtype: 'form',
            fileCount: 1,
            id: 'adpAttachmentFormid',
            border: false,
            api: {submit: 'iConnect.Attachments1.saveFile'},
            items: [
            {
                xtype: 'filefield',
                emptyText: 'Click Browse button to add a file',
                buttonText: 'Browse',
                width: 300,
                id: 'fileid',
                disabledCls: 'disabledControl',
                listeners:
                {
    change: function (file, value) {
        if (file.value != file.emptyText && file.value != "") {
            var grid = file.up("form").down("grid");
            var store = file.up("form").down("grid").getStore();  //get the store from the grid on the form
            var form = Ext.ComponentQuery.query('form[id="adpAttachmentFormid"]')[0];
            form.submit();
    
    
            store.add({
                objId: store.count() + 1,
                fileName: file.value,
                fileLink: file.value,
                version: 1,
                additionalInformation: "",
                attachedBy: "",
                isForInternalUseOnly: 0
            });
    
    
            grid.show();
            file.reset();
    
    
        }
    }
                }
            },
            {
                id: 'uxadpfileuploadgridid',
                xtype: 'uxadpfileuploadgrid',
                hidden: true
            }]
        }]
    Code:
    [DirectMethodForm]
    public JObject saveFile(HttpRequest request)
    {
        BaseForm baseFormObj = new BaseForm();
        string retMessage = string.Empty;
        string fileName = string.Empty;
        string focusId = ADPDS.Utility.Utility.DBNullToString(request["ObjectID"]);// case or sub case id.
        string loginName = baseFormObj.UserData.VisionLogin;
        ADPDS.Utility.FileSystem fileSystemObj = new ADPDS.Utility.FileSystem();
        string temporaryFileAttachmentPath = System.Configuration.ConfigurationManager.AppSettings["TemporaryAttachmentsPath"];//TemporaryAttachmentsPath
        string temporaryFolderPath = temporaryFileAttachmentPath + "\\" + loginName + "\\" + focusId;
    
    
        try
        {
    for (int i = 0; i < request.Files.Count; i++)
    {
        if (request.Files.Count > 0)
        {
    HttpPostedFile file = request.Files[i];
    if (file.ContentLength > 0)
    {
        fileName = Path.GetFileName(file.FileName);
        BinaryReader b = new BinaryReader(file.InputStream);
        byte[] binData = b.ReadBytes(file.ContentLength);
    
    
        fileSystemObj.CreateDirectory(temporaryFolderPath);
        fileSystemObj.ByteArrayToFile(temporaryFolderPath + "\\" + fileName, binData);
    }
        }
    }
        retMessage = " was successfully uploaded.";
        }
        catch (Exception ex)
        {
    ADPDS.CustomExceptionHandler.ExceptionHandler.HandleException(ex, "DBLog");
    return new JObject(
       new JProperty("success", false),
       new JProperty("file", fileName),
       new JProperty("message", "file failed to be uploaded."));
    
    
        }
    
    
        return new JObject(
           new JProperty("success", true),
           new JProperty("file", fileName),
           new JProperty("message", "file was successfully uploaded."));
    }

  3. #3
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    10,385
    Vote Rating
    264
      0  

    Default

    Are you getting anything helpful from the server response?

  4. #4
    Sencha User
    Join Date
    Aug 2012
    Posts
    8
    Vote Rating
    0
      0  

    Default

    Not sure what you mean, but the server does contain the HttpRequest object and since it does not find the HttpPostedFile data, it does not set the KObject to false.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •