Coder Social home page Coder Social logo

imageuploader's Introduction

ImageUploader

A library for uploading images to the server determined path & save path to the field on server DB :)

A

How to Use;

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
        implementation 'com.github.SPSpisoft:ImageUploader:Tag'
  }

sample :

xml:
<com.spisoft.ivuploader.imageUploader
android:id="@+id/iuLogo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="3dp"
android:paddingEnd="3dp"
app:CornerRadius="6dp"
app:StrokeColor="@android:color/darker_gray"
app:StrokeWidth="2"
app:SubTitle="@string/IuDescription"
app:Title="@string/logo" />
	
Code:		
  imageUploader vIuLogo = (imageUploader) findViewById(R.id.iuLogo);
  vIuLogo.url(MyUrlFiles+"api/").preview(MyStoreActivity.this, YOUR_PREVIEW_URL)
            .fileName(YOUR_FILE_NAME) // if not used fileName func save&set base fie name into server.
            .requestCode(new imageUploader.RequestMap(1, YOUR_REQUEST_ID), YOUR_CONDITION_TO_UPDATE_FIELD);

Sample server code [c# - web api];

[System.Web.Http.Route("api/upload")]
public async Task<HttpResponseMessage> PostImage(string mName, string mCode, string mWhere)
{
    string mPath = "";
    string mTbl = "", mFld = "";

  switch (mCode)
  {
      case YOUR_REQUEST_ID:
          mPath = Image_Banner_Path;
          mTbl = Tbl_Store;
          mFld = Tbl_Store_Fld_Banner;
          break;

      default:
          mCode = null;
          break;
  }

  try
  {
      if (!Request.Content.IsMimeMultipartContent() || mName == null)
          throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);

      var adPath = "_Files/Images/" + mPath; // images path
      var uploadPath = Path.Combine(HttpContext.Current.Server.MapPath("~/"+adPath));
      var multipartFormDataStreamProvider = new CustomUploadMultipartFormProvider(uploadPath, mName);
      await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);
      foreach (var key in multipartFormDataStreamProvider.FormData.AllKeys)
      {
          foreach (var val in multipartFormDataStreamProvider.FormData.GetValues(key))
          {
              Console.WriteLine(string.Format("{0}: {1}", key, val));
          }
      }

      var localFileName = multipartFormDataStreamProvider.FileData.ToString();
      if (mCode != null)
      {
          // UpdateWhere >> a function to update DB .. return (True/False)
          // mName >> YOUR_FILE_NAME
          // mWhare >> YOUR_CONDITION_TO_UPDATE_FIELD
          if(UpdateWhere(ConStr, mTbl, mFld + "='" + adPath + "/" + mName + "'", mWhare))
              return new HttpResponseMessage(HttpStatusCode.OK);
      }

      return new HttpResponseMessage(HttpStatusCode.Accepted);
  }
  catch (Exception e)
  {
      return new HttpResponseMessage(HttpStatusCode.NotImplemented)
      {
          Content = new StringContent(e.Message)
      };
  }

imageuploader's People

Contributors

spspisoft avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.