add the ability to upload a file with just a snipit of code

javascript / jquery (this example is using angularjs, could use $.post instead)

    $scope.uploadFile = function(files) {
        var $data = new FormData();
        $data.append("p_user_id", userID );
        $data.append("p_po_line_id", $scope.po_line_id);
        $data.append("p_filename", files[0]);

        $http.post("spep.spep_rfq_pkg.markup_ang_upload_attachment", $data, {
            withCredentials: true,
            headers: {''Content-Type'': undefined },
            transformRequest: angular.identity
        })
          .then(function onSuccess(response) {
            var data = response.data;
            var status = response.status;
            var statusText = response.statusText;
            var headers = response.headers;
            var config = response.config;
            $scope.getdata();
          }).catch(function onError(response) {
            var data = response.data;
            var status = response.status;
            var statusText = response.statusText;
            var headers = response.headers;
            var config = response.config;
          });

    };

HTML

<input type="file" name="file" onchange="angular.element(this).scope().uploadFile(this.files)"/>

DATABASE (using an Oracle procedure for this example)

	procedure markup_ang_upload_attachment(p_po_line_id in number ,p_user_id in number,p_filename in varchar2) as

		CURSOR FILE_DATA IS
		SELECT name, filename,MIME_TYPE, BLOB_CONTENT
		FROM FLOWS_FILES.WWV_FLOW_FILE_OBJECTS$
		WHERE name = p_FILENAME;
		 
		FILE_REC                FILE_DATA%ROWTYPE;
 
		PO_LINE_ATTACHMENT_ID   NUMBER;
			 
		X_SEQ_NUM               NUMBER;
		X_CREATED_BY            NUMBER;
		X_CATEGORY_ID           NUMBER;
		X_DESCRIPTION           VARCHAR2 (200);
		X_FILE_NAME             VARCHAR2 (200);			 
		PATH_NAME               VARCHAR2 (200);
		X_ATTACHMENT_NAME		VARCHAR2 (200);
		xblob                   BLOB;
   BEGIN
		xblob := EMPTY_BLOB ();
		DBMS_LOB.createtemporary (xblob, TRUE, 10);
		 
		X_ATTACHMENT_NAME := REPLACE (REPLACE (p_FILENAME, '&', '_'), '%', '_');
		OPEN FILE_DATA;
		FETCH FILE_DATA INTO FILE_REC;
		CLOSE FILE_DATA;
  ..... process the file

   end;

Leave a Reply