Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Problem in uploading a video file through node.acs

$
0
0

I am uploading a video file through node.acs. Videos with 1 or 2 mb gets uploaded easily but above that itgets upload but before it uploaded, is giving error that 'Error Occurred while uploading file'.

Here is my code.

<form id=imageform_<%=video.id%> name=imageform_<%=video.id%> method="POST" enctype="multipart/form-data" action="/api/uploadphoto"> <img id=image_<%=video.id%> src="images/upload.png" width="80" height="100" border="1" /> <input type="hidden" name="recordid" value='<%=video.id%>' > <input type="hidden" name="classname" value='Video' > <div id="progress" hidden="true" class="row-fluid"> <img id=image_<%=video.id%> src="images/uploading.gif" width="150" height="5" border="1" /> </div> <div id="file_input" class="row-fluid">
<input type="file" name="photo_file" id=photo_file_<%=video.id%> onchange="readImage(this,'<%=video.id%>')"/> </div> <button id="btnUpload" class="btn btn-primary" disabled onClick="formSubmitHandler1(this,'<%=video.id%>')">Upload</button>

function formSubmitHandler1(btn, recid) { // Get form element from document var formId = "#imageform_" + recid; var formObj = $(formId);

    formObj.submit(function(e)
    {
         e.preventDefault(); //Prevent Default action.
    });

    // Hide the upload button and input
    btn.style.display = 'none';
    formObj.find(&quot;#file_input&quot;).hide();

    // Show progress
    formObj.find(&quot;#progress&quot;).show();

    var formURL = formObj.attr(&quot;action&quot;);
    var formData = new FormData(formObj[0]);

    $.ajax({
        url: formURL,
        type: 'POST',
        data:  formData,
        mimeType:&quot;multipart/form-data&quot;,
        contentType: false,
        cache: false,
        processData:false,
        success: function(data, textStatus, jqXHR)
        {
            alert(&quot;Image uploaded successfully !&quot;);

            // Parse data sent by server into JSON
            var datajson = JSON.parse(data);

            // Set new image for this product
            var videoImgId = &quot;#video_image_&quot; + recid;
            $(videoImgId).attr('src',datajson.Video[0].photo_url);

            // Hide progress
            formObj.find(&quot;#progress&quot;).hide();

            // show upload button and file input
            btn.style.display = 'block';
            formObj.find(&quot;#file_input&quot;).show();
            formObj.find(&quot;#file_input&quot;)[0].children[0].value = '';

            // Disable upload button &amp; reset image
            formObj.find(&quot;#btnUpload&quot;).attr('disabled','disabled');
            var imgId = '#image_' + recid;
            $(imgId).attr('src',&quot;images/upload.png&quot;).width('100').height('100');

        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            alert(textStatus);
            console.log(errorThrown);
        }         
    });
}

Then it calls a function on js as follows

function uploadfile(req,res) { // Get the class name for custom object and it's ID to update it var objid = req.body.recordid; var objname = req.body.classname;

// console.log(require('path').dirname('config.json'));

var data = {
    session_id:req.session.session_id,
    name: 'A/V File',
    file: req.files.file
};

ACS.Files.create(data, function(e) {
    if(e.success &amp;&amp; e.success === true){

        ACS.Objects.update({
                session_id:req.session.session_id,
                classname:objname,
                id:objid,
                fields: {
                    file_id:e.files[0].id,
                    Status:'Uploaded',
            }
        },function(data) {
            if(data.success) {
                // console.log('Updated successfully:' + JSON.stringify(data));
                res.send(data);
                //res.redirect('/video');                   

            }else {
                console.log('Error:\n' +
                ((data.error &amp;&amp; data.message) || JSON.stringify(data)));
            }
        });       
    }else{
      logger.debug('Error: ' + JSON.stringify(e));
      req.session.flash = {msg:e.message, r:0};
      res.redirect('/');
    }
});

}


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>