{"action":"created","issue":{"url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/665","labels_url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/665/labels{/name}","comments_url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/665/comments","events_url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/665/events","html_url":"https://github.com/signalpoint/DrupalGap/issues/665","id":117747162,"number":665,"title":"image upload issue","user":{"login":"gireeshscs","id":3909035,"avatar_url":"https://avatars.githubusercontent.com/u/3909035?v=3","gravatar_id":"","url":"https://api.github.com/users/gireeshscs","html_url":"https://github.com/gireeshscs","followers_url":"https://api.github.com/users/gireeshscs/followers","following_url":"https://api.github.com/users/gireeshscs/following{/other_user}","gists_url":"https://api.github.com/users/gireeshscs/gists{/gist_id}","starred_url":"https://api.github.com/users/gireeshscs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gireeshscs/subscriptions","organizations_url":"https://api.github.com/users/gireeshscs/orgs","repos_url":"https://api.github.com/users/gireeshscs/repos","events_url":"https://api.github.com/users/gireeshscs/events{/privacy}","received_events_url":"https://api.github.com/users/gireeshscs/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/signalpoint/DrupalGap/labels/7.x-1.x","name":"7.x-1.x","color":"5319e7"},{"url":"https://api.github.com/repos/signalpoint/DrupalGap/labels/Support%20Request","name":"Support Request","color":"e102d8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-19T05:57:31Z","updated_at":"2015-11-19T13:41:16Z","closed_at":null,"body":"Hi\r\n\r\nI am using a custom drupalgap form with file field ,and i am saving image to public pathuing file_save.\r\nImages are uploading but when taken in browser it got corrupted.can you help me to resolve this issue. I am pasting code here.\r\n```\r\n var file = $(\"input[type=file]\")[0].files[0]; \r\n\t  //alert(file.name);\r\n\t // exit;\r\n\talert(form_state.values['image']);  \r\n\t // var file= form_state.values['image'];\r\n\t //alert( form_state.values['image']);\r\n\t  var form_data = new FormData();                  // Creating object of FormData class\r\n\tform_data.append(\"file\", file);\r\n\t  \r\n\t      var d = new Date();\r\n      var image_file_name = Drupal.user.name + '_' + d.valueOf() + file.name;\r\n      // Build the data for the file create resource. If it's private, adjust\r\n      // the filepath.\r\n\t  \r\n      var file = {\r\n        file: {\r\n\t\t//$(\"input[type=file]\")[0].files[0];  \r\n          file: form_state.values['image'],\r\n          filename: image_file_name,\r\n          filepath: 'public://' + image_file_name\r\n        }\r\n      };\r\n      if (!empty(Drupal.settings.file_private_path)) {\r\n        file.file.filepath = 'private://' + image_file_name;\r\n      }\r\n      // Change the loader mode to saving, and save the file.\r\n      drupalgap.loader = 'saving';\r\n      processed_an_image = true;\r\n      \r\n      var profile_img_uri = 'public://' + image_file_name;\r\n\t  //\r\n//\tvar profile_img = 1;\r\n      \r\n\t  file_save(file, {\r\n\t\t async: false, \r\n\t\t//data: data,\t \r\n\t\t//method: 'POST',\r\n\t//\tpath: 'drupalgap/file.json',\r\n            success: function(result) {\r\n              try {\r\n\t\t      //alert(result.fid);\r\n\t\t      var fid=result.fid;\r\n\t\t      //alert(profile_img_uri);\r\n\t\t \r\n                // Set the hidden input and form state values with the file id.\r\n                //var element_id = drupalgap_form_get_element_id(new_upload_image, form.id);\r\n                $('input#fid').val(result.fid);\r\n                //form_state.values['new_upload_image'][lng][0] = result.fid;\r\n                //if (options.success) { options.success(); }\r\n\t\t       console.log('success');\r\n              }\r\n              catch (error) {\r\n                console.log('_image_field_form_process - success - ' + error);\r\n              }\r\n            }\r\n        });\r\n```\r\nThanks in advance,\r\nGireesh"},"comment":{"url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/comments/158059501","html_url":"https://github.com/signalpoint/DrupalGap/issues/665#issuecomment-158059501","issue_url":"https://api.github.com/repos/signalpoint/DrupalGap/issues/665","id":158059501,"user":{"login":"signalpoint","id":671140,"avatar_url":"https://avatars.githubusercontent.com/u/671140?v=3","gravatar_id":"","url":"https://api.github.com/users/signalpoint","html_url":"https://github.com/signalpoint","followers_url":"https://api.github.com/users/signalpoint/followers","following_url":"https://api.github.com/users/signalpoint/following{/other_user}","gists_url":"https://api.github.com/users/signalpoint/gists{/gist_id}","starred_url":"https://api.github.com/users/signalpoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/signalpoint/subscriptions","organizations_url":"https://api.github.com/users/signalpoint/orgs","repos_url":"https://api.github.com/users/signalpoint/repos","events_url":"https://api.github.com/users/signalpoint/events{/privacy}","received_events_url":"https://api.github.com/users/signalpoint/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T13:41:16Z","updated_at":"2015-11-19T13:41:16Z","body":"You need to base 64 encode the image, that is most likely why it is corrupt. Replace `form_state.values['image']` with a base 64 encoded image, and it'll work."}}