Monday 5 August 2019

Upload image using ajax request in rails

          <%=  file_field_tag :customer_profile, id: "customer_profile"  %>           

          var formData = new FormData();
          custProfile  =$("#customer_profile")[0].files[0]
          formData.append("device_img", custProfile);
          $.ajax({
          url: "<%=  upload_image_customer_path(id: params[:id]) %>",
          type: 'POST',
          dataType: 'json',
          data: formData,
          contentType: false,
          processData: false,
          cache : false,
          success: function(data){
            if(data["msg"] == true){
              alert(success)
             }
            },
           error: function(data){
             console.log(data); 
            }
          });

Friday 2 August 2019

Image convert in base64 in rails

require "base64"

file_url = "https://s3.ap-south-1.amazonaws.com/on-store-billing/uploads/insurance/servify_device_image/58/1__2_.jpeg"

encoded_string = Base64.encode64(open(file_url) { |io| io.read })

decode_img= Base64.decode64(encoded_string)

below given method write/create image with name image.png in directory

File.open(‘image.png’, ‘wb’) { |f| f.write(decode_img) }

Revert last commit or second last and more....

 Git revert commit_id -m 1 this command willl revert last commit  Git revert commit_id -m 2 this command will revert second commit with same...