[opencms-dev] How can send binary file (image) via form, for put folder in opencms?

Deiverson Silveira deiverson at solutioncms.com
Wed Jul 9 18:24:16 CEST 2008


Imagine scene:

I have html form:
<form action="recordPhoto.jsp" method="POST">
                <label>*Name for photo:</label>
                <input  name="txtName" id="txtName" type="text" />
                <br>
                <label>Photo:</label>
                <input name="uploadPhoto" type="file" />
                <input name="Send" value="Send" type="submit'>
</form>

And my recordPhoto.jsp:

                String userCurrent =
cms.getRequestContext().currentUser().getName().toString();
                if(userCurrent.equals("Guest")){
                   cmsObject.loginUser("userforphotos", "userforphotos");
                }
        CmsProject cmsproject = cmsObject.readProject("Offline");
        cmsObject.getRequestContext().setCurrentProject(cmsproject);
        cmsObject.getRequestContext().setSiteRoot("/myproject/");

String Photo = null;
String Name = "";
try{
  Photo = (String)request.getAttribute("uploadPhoto");
 }catch(Exception exp){
  Photo = "/";
 }

Locale locale = new java.util.Locale("en");
try{
CmsXmlContentDefinition cd =  CmsXmlContentDefinition.unmarshal(cmsObject,
"/system/modules/my.project/schema/myPhoto.xsd");
CmsXmlContent xmlcontent =
CmsXmlContentFactory.createDocument(cmsObject,locale,org.opencms.main.OpenCms.getSystemInfo().getDefaultEncoding(),cd);

xmlcontent.getValue("Name", Locale.ENGLISH).setStringValue(cmsObject,
String.valueOf(Name));
xmlcontent.getValue("Photo", Locale.ENGLISH).setStringValue(cmsObject,
String.valueOf(Photo));
byte[] content = xmlcontent.marshal();

String folder = "/myPhotos/";


   String nameFile = "testPhoto.html";
   cmsObject.createResource(folder + nameFile,
org.opencms.main.OpenCms.getResourceManager().getResourceType("xmlcontent").getTypeId(),content,new
ArrayList());

// NOW I NEED STORE IN FOLDER "/myPhotos/" the photo send via RequestHTTP,
how can this is? Store binary send request form?
 }

You can imagine one suggest/alternative/way for i can success for store file
send extern in put opencms?

Thank biggers, KR,

Deivs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20080709/102d29b3/attachment.htm>


More information about the opencms-dev mailing list