Upload multiple images (uploaded to the server), mix text and text in the content box, and enter the content in the clob Field

Source: Internet
Author: User

When users want to insert images, they first upload several images to the server. If the image is successfully inserted, the server returns the URL of the image on the server, and then automatically writes the URL to the edited content using Js. And enter a large field.

<%
Int itotalbyte, itotalread, ireadbyte;
Itotalbyte = request. getcontentlength ();
Itotalread = 0;
Ireadbyte = 0;
Byte [] buffer = new byte [itotalbyte];
If (itotalbyte> 0)
{
For (; itotalread <itotalbyte; itotalread ++ = ireadbyte)
{
Try
{
Ireadbyte = request. getinputstream (). Read (buffer, itotalread, itotalbyte-itotalread );
}
Catch (exception E)
{
E. printstacktrace ();
}
}
String strcontenttype = request. getcontenttype ();
// Start Data Processing
String strbuffer = new string (buffer );
%> <! -- <Br/> form data: <br/> strbuffer <br/> --> <%
String strboundary = "--" + strcontenttype. substring (strcontenttype. lastindexof ("=") + 1, strcontenttype. Length ());
String strarray [] = strbuffer. Split (strboundary );

String strsubstring;
Int ibegin, iend;
Ibegin = 0; iend = 0;
String strfieldname = "";
String strfieldvalue = "";
String strfilepath = "";
String strfilename = "";
String strfiletype = "";
Boolean btrue;
Btrue = false;
Int ilocation = 0;
For (INT iindex = 1; iindex <strarray. Length-1; iindex ++)
{
Strsubstring = strarray [iindex];
Ibegin = strsubstring. indexof ("name = \" ", 0 );
If (ibegin! =-1)
{
Strfieldname = ""; strfieldvalue = "";
Strfilepath = ""; strfilename = ""; strfiletype = "";
Iend = strsubstring. indexof ("\" ", ibegin + 6 );
Strfieldname = strsubstring. substring (ibegin + 6, iend );
Ibegin = strsubstring. indexof ("filename = \" ", 0); If (ibegin! =-1)
{
Btrue = true;
}
Iend = strsubstring. indexof ("\ r \ n", 0 );
If (btrue = true)
{
// File path
Strfilepath = strsubstring. substring (ibegin + 10, strsubstring. indexof ("\" ", ibegin + 10); strfilename = strfilepath. substring (strfilepath. lastindexof ("\") + 1 );
Strfiletype = strsubstring. substring (strsubstring. indexof ("Content-Type:") + 14, strsubstring. indexof ("\ r \ n "));
%> <! -- <Br/> file type: <br/> strfiletype <br/> --> <%
// File data
Ibegin = strsubstring. indexof ("\ r \ n", ibegin );
Strfieldvalue = strsubstring. substring (ibegin + 4 );
Strfieldvalue = strfieldvalue. substring (0, strfieldvalue. lastindexof ("\ n")-1 );
%> <! -- <Br/> file path: <br/> strfilepath <br/> file name: <br/> strfilename <br/> --> <%
Byte [] pfile = strfieldvalue. getbytes ();
Byte [] pfileextend = new byte [pfile. Length];
Ilocation = strbuffer. indexof ("filename = \" ", ilocation );
For (INT kindex = ilocation; kindex <iTotalByte-2; kindex ++)
{
If (buffer [kindex] = 13 & buffer [kindex + 2] = 13)
{Ilocation = kindex + 4; break ;}
}
For (INT nindex = 0; nindex <pfile. length; nindex ++)
{
Pfileextend [nindex] = buffer [ilocation + nindex];
}
/*
// Save to local disk;
Fileoutputstream pfileoutputstream = new fileoutputstream ("f :\\ site_app \ uploadfile \" + strfilename );
Pfileoutputstream. Write (pfileextend );
Pfileoutputstream. Close ();
*/
Session. putvalue (strfieldname + "_ filetype", strfiletype );
Session. putvalue (strfieldname + "_ filepath", strfilepath );
Session. putvalue (strfieldname + "_ filename", strfilename );
Session. putvalue (strfieldname, pfileextend );
}
Else
{
Strfieldvalue = strsubstring. substring (iend + 4 );
Strfieldvalue = strfieldvalue. substring (0, strfieldvalue. lastindexof ("\ n")-1 );
Session. putvalue (strfieldname, strfieldvalue );
}
Btrue = false;
}
%> <! -- <Br/> form Domain Name: <br/> strfieldname <br/> form field value: <br/> strfieldvalue <br/> --> <%
}
// Data processing ends
}
%>

So (string) session. getvalue ("form domain name") returns the form field value, while (byte []) session. the byte array returned by getvalue ("File Upload control domain name") can use new bytearrayinputstream (byte []) to call updatebinarystream to update it to the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.