File Upload File Renaming
I was wondering if anyone knows how to set up a trigger to automatically rename a file on upload to change spaces into underscores using DToolbox image and resize feature. An example is from "My picture.jpg" to "My_picture.jpg". I also wonder if this could be part of a form validation? Maybe using a spry widget?
I have no experience with triggers, and especially the adobe tng.FileUpload.class.php file (which I assume is where to change the trigger? or maybe it's in the tng.ImageUpload.class.php file?)
Thanks for the help!
-Chris
Hi Chris,
fotunately I already made such a modification to ADDT´s predecessor "MX Kollection", and as the core files didn´t change, it will assumingly work the same:
1. add the following function to the file "includes/common/KT_functions.inc.php":
replace all chars from uploaded filenames other than alpha-numeric and "_" and "-" and "." with an underscore (_)
function KT_websafe_filename($text) {
return preg_replace("/[^a-zA-Z0-9\-_\.]+/", "_", $text);
2. change line 120 in file "includes/common/lib/file_upload/KT_FileUpload.class.php":
old: $fileName = KT_replaceSpecialChars($fileName, 'filter');
new: $fileName = KT_websafe_filename($fileName, 'filter');
This modification will of course *always* be renaming the uploaded file accordingly -- but you´ll need no fancy trigger and anything else.
Please backup the 2 original files !!
Günter Schenk
Adobe Community Expert, Dreamweaver
Similar Messages
-
File upload custom renaming not working with {KT_ext}
Hi,
I used many times custom renaming with file upload, and used {KT_ext} for file's extension, but in first ADDT project is not working. I use this:
$uploadObj->setRenameRule("{GET.id_cd}_{track}.{KT_ext}");
Does anybody know if {KT_ext} is broken in ADDT?
Thank you,
RubenHi Günter,
{track} and {id_track} are both table fields, and setRenameRule worked right with both, but it didn't with {KT_ext}.
I've changed {track} with {id_track} in first page, and it stills fail to put extension.
But maybe is this, in first page the column for Update Transaction is like this
$upd_cds_peces->addColumn("mp3", "FILE_TYPE", "POST", "mp3");
and in the second page (where it works right) is
$upd_cds_peces->addColumn("mp3", "FILE_TYPE", "FILES", "mp3");
Althought in both cases the file is uploaded and DDBB field is filled, maybe in first case the TNG doesn't expect a file and cannot find its extension.
I'll try to change it,
thanks,
Ruben
Edit: Yes, it was this... Now it works. Thank you Günter for your help! -
File Upload - File Name in Hebrew problem
Hi all,
I am using file upload with IWDResource in NW04s and while loading files with hebrew encoding I am getting gibrish when using
getResourceName()
method.
I also tried working with data and fileName properties - both giving null.
Any ideas?
Thanks,
AviadHi Levy,
Use this code in action button for upload a file
Here up is a context attribute of type "com.sap.ide.webdynpro.uielementdefinitions.Resource"
It is to be bind with upload UI element property called "resource"
InputStream text = null;
int temp = 0;
try
File file = new File(wdContext.currentContextElement().getUp().getResourceName());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getUp()!=null)
text = wdContext.currentContextElement().getUp().read(false);
while((temp=text.read())!=-1)
op.write(temp);
op.flush();
op.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
catch(Exception e)
e.printStackTrace(); -
File uploading file through RFC
Hi All ,
I am trying to upload file using FM GUI_Upload ,its working fine when i run in sap , But throws a Dump if the file path is passed from .net . The same file path when i pass it in sap directly it works fine .
the error :
OBJECTS_OBJREF_NOT_ASSIGNED in FM DP_CONTROL_ASSIGN_TABLE
Any Help will be great .
Thanks
VinayHi use this
reward if help
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = FILENAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = BUFFER
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22 -
Problem with file upload: File to big...
Hi,
when I try to upload a file of 6MB I get an error that the file is to big. I changed the web.xml but maybe I forgot something?
I use Jdeveloper 11.1.1.2.0
This is in my web.xml:
<context-param>
<param-name>oracle.adf.view.faces.UPLOAD_MAX_MEMORY</param-name>
<param-value>51200000</param-value>
</context-param>
<context-param>
<!-- Maximum disk space per request (in bytes) - Uploadfiles larger than this will force an Exception -->
<param-name>oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE</param-name>
<!-- Use 500M -->
<param-value>512000000</param-value>
</context-param> The total web.xml:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<context-param>
<param-name>oracle.adf.view.faces.UPLOAD_MAX_MEMORY</param-name>
<param-value>51200000</param-value>
</context-param>
<context-param>
<!-- Maximum disk space per request (in bytes) - Uploadfiles larger than this will force an Exception -->
<param-name>oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE</param-name>
<!-- Use 500M -->
<param-value>512000000</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>If this parameter is true, there will be an automatic check of the modification date of your JSPs, and saved state will be discarded when JSP's change. It will also automatically check if your skinning css files have changed without you having to restart the server. This makes development easier, but adds overhead. For this reason this parameter should be set to false when your application is deployed.</description>
<param-name>org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>Whether the 'Generated by...' comment at the bottom of ADF Faces HTML pages should contain version number information.</description>
<param-name>oracle.adf.view.rich.versionString.HIDDEN</param-name>
<param-value>false</param-value>
</context-param>
<filter>
<filter-name>JpsFilter</filter-name>
<filter-class>oracle.security.jps.ee.http.JpsFilter</filter-class>
<init-param>
<param-name>enable.anonymous</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>remove.anonymous.role</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>trinidad</filter-name>
<filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class>
</filter>
<filter>
<filter-name>ADFLibraryFilter</filter-name>
<filter-class>oracle.adf.library.webapp.LibraryFilter</filter-class>
</filter>
<filter>
<filter-name>adfBindings</filter-name>
<filter-class>oracle.adf.model.servlet.ADFBindingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>JpsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>trinidad</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>ADFLibraryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>adfBindings</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>adfBindings</filter-name>
<servlet-name>adfAuthentication</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<listener>
<listener-class>oracle.adf.mbean.share.connection.ADFConnectionLifeCycleCallBack</listener-class>
</listener>
<listener>
<listener-class>oracle.adf.mbean.share.config.ADFConfigLifeCycleCallBack</listener-class>
</listener>
<listener>
<listener-class>oracle.bc4j.mbean.BC4JConfigLifeCycleCallBack</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>resources</servlet-name>
<servlet-class>org.apache.myfaces.trinidad.webapp.ResourceServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BIGRAPHSERVLET</servlet-name>
<servlet-class>oracle.adfinternal.view.faces.bi.renderkit.graph.GraphServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BIGAUGESERVLET</servlet-name>
<servlet-class>oracle.adfinternal.view.faces.bi.renderkit.gauge.GaugeServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>MapProxyServlet</servlet-name>
<servlet-class>oracle.adfinternal.view.faces.bi.renderkit.geoMap.servlet.MapProxyServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>GatewayServlet</servlet-name>
<servlet-class>oracle.adfinternal.view.faces.bi.renderkit.graph.FlashBridgeServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>adflibResources</servlet-name>
<servlet-class>oracle.adf.library.webapp.ResourceServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>adfAuthentication</servlet-name>
<servlet-class>oracle.adf.share.security.authentication.AuthenticationServlet</servlet-class>
<init-param>
<param-name>success_url</param-name>
<param-value>/pages/Tickets.jspx </param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/adf/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/afr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>BIGRAPHSERVLET</servlet-name>
<url-pattern>/servlet/GraphServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>BIGAUGESERVLET</servlet-name>
<url-pattern>/servlet/GaugeServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MapProxyServlet</servlet-name>
<url-pattern>/mapproxy/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>resources</servlet-name>
<url-pattern>/bi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GatewayServlet</servlet-name>
<url-pattern>/flashbridge/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adflibResources</servlet-name>
<url-pattern>/adflib/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adfAuthentication</servlet-name>
<url-pattern>/adfAuthentication</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>adfAuthentication</web-resource-name>
<url-pattern>/adfAuthentication</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>valid-users</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/LoginPage.jspx</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>valid-users</role-name>
</security-role>
</web-app>Hi,
It works for me, the only difference is I am using parameters from trinidad's packages
<context-param>
<!-- Maximum memory per request (in bytes) -->
<param-name>org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY</param-name>
<!-- Use 500K -->
<param-value>512000</param-value>
</context-param>
<context-param>
<!-- Maximum disk space per request (in bytes) -->
<param-name>org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE</param-name>
<!-- Use 5,000K -->
<param-value>5120000</param-value>
</context-param>Try it, maybe it will work.
Pedja -
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9
A couple of days ago after the latest update every time I try and upload a file to a web site the file browse has started suddenly to close after a few seconds before allowing me to choose a file.Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9
A couple of days ago after the latest update every time I try and upload a file to a web site the file browse has started suddenly to close after a few seconds before allowing me to choose a file. -
Fileaccess.httpUploadBean doesn't upload file in Jdevelper 9.0.3
Hi,
I am using Jdevelper 9.0.3 to develop a jsp Based File Upload Utility.
I have attached Liberary "JSP RUNTIME" which reffers to "ojsp.jar","ojsputil.jar","oc4j.jar","servlet.jar","ojc.jar".
while running the code for file upload, file doesn't get uploaded. I am not getting any exceptions too.
But the same pease of code with same liberary "JSP RUNTIME" is working absolutly fine(Uploading File), when i am running it using Jdeveloper10.1.2, and This is Strange to me.Actualy i need to use Jdeveloper9.0.3 only.Please let me know if any patch is required to apply in Jdeveloper9.0.3.
Please find the code below and help.
fileaccess.properties
fileaccess.basedir = C:/
fileUpload.jsp
<html><body>
<form name = "formname" action="beanUploadExample.jsp" method=POST ENCTYPE="multipart/form-data" />
<br>MailID: <INPUT TYPE="text" NAME="strMailId" />
<br> File to upload: <INPUT TYPE="FILE" NAME="File" SIZE="50" MAXLENGTH="120" >
<br><INPUT TYPE="Submit" NAME="Submit" VALUE="Send" >
<INPUT type="reset" name="reset" value = "Cancel">
</form>
</body></html>
beanUploadExample.jsp
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page language="java"
import="java.util.*,java.io.*, oracle.jsp.webutil.fileaccess.*" %>
<html><body>
<SCRIPT language="JavaScript">
function formAction()
if (document.upForm.forward.value == "true")
{//tOMORROW PASS THE FILE NAME WITH ACTION PARAM
//alert("Submit");
document.upForm.action = "uploadco"
document.upForm.submit();
</SCRIPT>
<Form name="upForm" method ="post" > <!--action ="beanUploadExample.jsp" >-->
<%
String userdir = "Test";
String strFlag = "";
String strFileName ="";
String strDirName ="";
String strAbsoluteName ="";
%>
<jsp:useBean id="upbean"
class="oracle.jsp.webutil.fileaccess.HttpUploadBean" >
<jsp:setProperty name="upbean" property="destination" value="<%=userdir%"/>
</jsp:useBean>
<%
try{
upbean.setBaseDir(application, request);
String str = upbean.getDestination();
// application.getServletContextName();
//out.println("The Servlet Context is "+strContext) ;
out.println("The value of Destination is "+str) ;
upbean.upload(request);
String name = upbean.getParameter("strMailId");
out.println("name-----:::::: "+name) ;
String strDestType = upbean.getDestinationType();
out.println("strDestType-----:::::: "+strDestType) ;
Enumeration fileNames = upbean.getFileNames();
while (fileNames.hasMoreElements()) {
strFlag = "true";
strFileName = (String)fileNames.nextElement();
out.println("strFileName File Name Is:::::"+strFileName);
strAbsoluteName = strFileName.substring(4,strFileName.length());
catch(IOException ex)
out.println("IOException is =="+ex.toString());
catch(Exception ex)
out.println("IOException is =="+ex.toString());
%>
<table width = 50% align="center" >
<tr>
<td align ="center"><input type = "Button" name ="Submit" value="Ok" onclick="formAction()" ></td></tr></table>
</Form>
</body></html>Hi,
I am using Jdevelper 9.0.3 to develop a jsp Based File Upload Utility.
I have attached Liberary "JSP RUNTIME" which reffers to "ojsp.jar","ojsputil.jar","oc4j.jar","servlet.jar","ojc.jar".
while running the code for file upload, file doesn't get uploaded. I am not getting any exceptions too.
But the same pease of code with same liberary "JSP RUNTIME" is working absolutly fine(Uploading File), when i am running it using Jdeveloper10.1.2, and This is Strange to me.Actualy i need to use Jdeveloper9.0.3 only.Please let me know if any patch is required to apply in Jdeveloper9.0.3.
Please find the code below and help.
fileaccess.properties
fileaccess.basedir = C:/
fileUpload.jsp
<html><body>
<form name = "formname" action="beanUploadExample.jsp" method=POST ENCTYPE="multipart/form-data" />
<br>MailID: <INPUT TYPE="text" NAME="strMailId" />
<br> File to upload: <INPUT TYPE="FILE" NAME="File" SIZE="50" MAXLENGTH="120" >
<br><INPUT TYPE="Submit" NAME="Submit" VALUE="Send" >
<INPUT type="reset" name="reset" value = "Cancel">
</form>
</body></html>
beanUploadExample.jsp
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page language="java"
import="java.util.*,java.io.*, oracle.jsp.webutil.fileaccess.*" %>
<html><body>
<SCRIPT language="JavaScript">
function formAction()
if (document.upForm.forward.value == "true")
{//tOMORROW PASS THE FILE NAME WITH ACTION PARAM
//alert("Submit");
document.upForm.action = "uploadco"
document.upForm.submit();
</SCRIPT>
<Form name="upForm" method ="post" > <!--action ="beanUploadExample.jsp" >-->
<%
String userdir = "Test";
String strFlag = "";
String strFileName ="";
String strDirName ="";
String strAbsoluteName ="";
%>
<jsp:useBean id="upbean"
class="oracle.jsp.webutil.fileaccess.HttpUploadBean" >
<jsp:setProperty name="upbean" property="destination" value="<%=userdir%"/>
</jsp:useBean>
<%
try{
upbean.setBaseDir(application, request);
String str = upbean.getDestination();
// application.getServletContextName();
//out.println("The Servlet Context is "+strContext) ;
out.println("The value of Destination is "+str) ;
upbean.upload(request);
String name = upbean.getParameter("strMailId");
out.println("name-----:::::: "+name) ;
String strDestType = upbean.getDestinationType();
out.println("strDestType-----:::::: "+strDestType) ;
Enumeration fileNames = upbean.getFileNames();
while (fileNames.hasMoreElements()) {
strFlag = "true";
strFileName = (String)fileNames.nextElement();
out.println("strFileName File Name Is:::::"+strFileName);
strAbsoluteName = strFileName.substring(4,strFileName.length());
catch(IOException ex)
out.println("IOException is =="+ex.toString());
catch(Exception ex)
out.println("IOException is =="+ex.toString());
%>
<table width = 50% align="center" >
<tr>
<td align ="center"><input type = "Button" name ="Submit" value="Ok" onclick="formAction()" ></td></tr></table>
</Form>
</body></html> -
Unable to upload Files to child site collection using REST
Dear All,
I referred this article http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.aspx for uploading documents to SP Document Library and it works fine for any document library under the root site collection(
for example "http://<server name>/Shared Documents" but when i upload the same document to one of the sub site collection created using Managed Path( the site collection path is "http://<server name>/files/Case" and the library
name is "records") it fails and i get below error:
The security validation for this page is invalid. Click Back in your
Web browser, refresh the page, and try your operation again, Error Code -2130575251 Microsoft.SharePoint.SPException"
Any help suggestion to resolve this? I've almost tried everything to resolve this issue but no luck.. appreciate any help
for this..
Regards,
VishalHi,
According to your post, my understanding is that you had an issue uploading files to subsite using REST.
I had made a simple code demo below, it will upload a file to Document Library after you make your selection with the File control.
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function uploadFile(){
//alert(2);
if (document.getElementById("file").files.length === 0) {
alert('No file was selected');
return;
var parts = document.getElementById("file").value.split("\\");
var filename = parts[parts.length - 1];
var file = document.getElementById("file").files[0];
uploadFileSync("http://YourSite", "Documents", filename, file);
//Upload file synchronously
function uploadFileSync(spWebUrl , library, filename, file)
//alert(3);
var reader = new FileReader();
reader.onloadend = function(evt)
if (evt.target.readyState == FileReader.DONE)
var buffer = evt.target.result;
var completeUrl = spWebUrl
+ "/_api/web/lists/getByTitle('"+ library +"')"
+ "/RootFolder/Files/add(url='"+ filename +"',overwrite='true')?"
+ "@TargetLibrary='"+library+"'&@TargetFileName='"+ filename +"'";
$.ajax({
url: completeUrl,
type: "POST",
data: buffer,
async: false,
processData: false,
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-length": buffer.byteLength
complete: function (data) {
//uploaded pic url
console.log(data.responseJSON.d.ServerRelativeUrl);
error: function (err) {
alert('failed');
reader.readAsArrayBuffer(file);
</script>
<input type="file" id='file' onchange="uploadFile()"/>
Thanks,
Jason
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Jason Guo
TechNet Community Support -
Hi all,
I need to upload file from user local computer into Web Dynpro context, but standard FileUpload component doesn't look very "attractive" to me. There are 3 main reasons:
1. when user don't use Browse functionality, but he/she types directly for example == "xxxx" (not valid absolute windows path) into input field of FU Component and then click Upload, application freeze - and loading that 'file' forever.....
2. don't know how to specify custom file types in showed FileChooser (predefined are AllFiles, Pictures, HTML)
3. Browse label is not internationalized, no possibility to change that text (and that button also looks "different" )
How can I eliminate these minuses, or is here alternative solution for file uploading file in WD? My customer environment is NW 2004.
Regards,
JurajDynpro UI elements has limitations. But we can use them the way we want within these limitations.
1. when user don't use Browse functionality, but he/she types directly for example == "xxxx" (not valid absolute windows path) into input field of FU Component and then click Upload, application freeze - and loading that 'file' forever.....
If there is a fixed place to hold the documents, we can prefix the path upto the filename.
2. don't know how to specify custom file types in showed FileChooser (predefined are AllFiles, Pictures, HTML)
we can get the MIME type from the resource. And further processing can be restricted.
3. Browse label is not internationalized, no possibility to change that text (and that button also looks "different" )
I Agree that we can't change "Browse", but still we can have the orientation, if your browser is Arabic, it got aligned at right hand side.
thread:
nikhil
Edited by: Nikhil ßos on Jul 3, 2008 1:07 PM -
Help:simple file upload example not working
Request input on what's wrong with this -
Using JDeveloper 10G.
1) I created a simple jsp file upload file using the OJSP
File Access Tag library options. With empty JSP file,I
dropped in the httpUploadForm and the httpUpload tags.
Now when I run this I get the following error stack on
the web page.
javax.servlet.jsp.JspTagException: Posted content type isnt multipart/form-data at oracle.jsp.webutil.fileaccess.tagext.HttpUploadTag.doStartTag(HttpUploadTag.java:130)at test4.jspService(test4.jsp:10)[test4.jsp]
2)Now if I use a simple JSP without the tag library - the
page fails to display. Found that commenting out the
line "upbean.upload()" lets the page run and atleast
show me the upload form. What's wrong with this
standard example from the OC4J documentation -
<%@ page import =
"javax.servlet.http.*,
java.io.*,
java.util.*,
oracle.jsp.webutil.fileaccess.*;" language="java" session="true" contentType="text/html;charset=windows-1252"
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Upload</title>
</head>
<body>
<% String userdir = "mydir"; %>
<form action="pUpload.jsp" ENCTYPE="multipart/form-data" method=POST>
<br>
File to upload: <INPUT TYPE="FILE" NAME="File" SIZE="50" MAXLENGTH="120" >
<br>
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Send">
</form>
<jsp:useBean id="upbean" class="oracle.jsp.webutil.fileaccess.HttpUploadBean" >
<jsp:setProperty name="upbean" property="destination" value="<%= userdir %>" />
</jsp:useBean>
<% upbean.setBaseDir(application, request);
//upbean.upload(request);
%>
</body>
</html>It's not clear from your post, but are you aware that the
documentation is really showing multiple files?
The doc examples are based on the ones you can try out by downloading the ojspdemos.ear file.
They use discrete steps. For example, the fileUploadIndex.html contains the following
This will call the form and set the action in the form to call the tag upload jsp file. The form will do the multi-part post and the tag upload file does display the text after the <upload:httpUpload> tag. I just re-ran the example to be sure.
The same basic mechanism applies to the upload bean. That is it is called via:
This is the only way that these can work because the upload code (beans & tags) both require a multi-part post. I hope this helps -
Rename file extension during a file upload ??
I need to rename the extension of a file at some point during the file upload. I am not sure where to do this at.
The file needs to be renamed before it is written to the directory.
Basically, the file will come in with a .txt or .doc type. Based on a users profile, I will change the type to a non-relavent number such as 1111.
Here is my upload servlet. Can you tell me where to change the type so it will write the file with the new extension?
Thanks.
public class FileExport {
//restrict upload files to 1 Meg
private static final int DEFAULT_MAX_POST_SIZE = 1024 * 1024;
private static final String NO_FILE = "unknown";
private HttpServletRequest req;
private File dir;
private int maxSize;
private Hashtable parameters = new Hashtable(); // name - Vector of values
private Hashtable files = new Hashtable(); // name - UploadedFile
public FileExport(HttpServletRequest request,
String saveDirectory) throws IOException {
this(request, saveDirectory, DEFAULT_MAX_POST_SIZE);
// request the servlet request
// saveDirectory = directory in which to save any uploaded files
// maxPostSize = maximum size of the POST content
public FileExport(HttpServletRequest request,
String saveDirectory,
int maxPostSize) throws IOException {
// check values
if (request == null)
throw new IllegalArgumentException("request cannot be null");
if (saveDirectory == null)
throw new IllegalArgumentException("saveDirectory cannot be null");
if (maxPostSize <= 0) {
throw new IllegalArgumentException("maxPostSize must be positive");
// Save the request, dir, and max size
req = request;
dir = new File(saveDirectory);
maxSize = maxPostSize;
// Check saveDirectory is truly a directory
if (!dir.isDirectory())
throw new IllegalArgumentException("Not a directory: " + saveDirectory);
// Check saveDirectory is writable
if (!dir.canWrite())
throw new IllegalArgumentException("Not writable: " + saveDirectory);
// Now parse the request saving data to "parameters" and "files";
// write the file contents to the saveDirectory
readRequest();
public FileExport(ServletRequest request,
String saveDirectory) throws IOException {
this((HttpServletRequest)request, saveDirectory);
public FileExport(ServletRequest request,
String saveDirectory,
int maxPostSize) throws IOException {
this((HttpServletRequest)request, saveDirectory, maxPostSize);
// Returns the names of all the parameters as an Enumeration of
// Strings. It returns an empty Enumeration if there are no parameters.
public Enumeration getParameterNames() {
return parameters.keys();
// Returns the names of all the uploaded files as an Enumeration of
// Strings. It returns an empty Enumeration if there are no uploaded
// files. Each file name is the name specified by the form, not by
// the user.
public Enumeration getFileNames() {
return files.keys();
// Returns the value of the named parameter as a String, or null if
// the parameter was not sent or was sent without a value.
public String getParameter(String name) {
try {
Vector values = (Vector)parameters.get(name);
if (values == null || values.size() == 0) {
return null;
String value = (String)values.elementAt(values.size() - 1);
return value;
catch (Exception e) {
return null;
// Returns the values of the named parameter as a String array, or null if
// the parameter was not sent.
public String[] getParameterValues(String name) {
try {
Vector values = (Vector)parameters.get(name);
if (values == null || values.size() == 0) {
return null;
String[] valuesArray = new String[values.size()];
values.copyInto(valuesArray);
return valuesArray;
catch (Exception e) {
return null;
// Returns the filesystem name of the specified file, or null if the
// file was not included in the upload. A filesystem name is the name
// specified by the user. It is also the name under which the file is
// actually saved.
public String getFilesystemName(String name) {
try {
UploadedFile file = (UploadedFile)files.get(name);
return file.getFilesystemName(); // may be null
catch (Exception e) {
return null;
// Returns the content type of the specified file (as supplied by the
//client browser), or null if the file was not included in the upload.
public String getContentType(String name) {
try {
UploadedFile file = (UploadedFile)files.get(name);
return file.getContentType(); // may be null
catch (Exception e) {
return null;
// Returns a File object for the specified file saved on the server's
// filesystem, or null if the file was not included in the upload.
public File getFile(String name) {
try {
UploadedFile file = (UploadedFile)files.get(name);
return file.getFile(); // may be null
catch (Exception e) {
return null;
// method that actually parses the request.
protected void readRequest() throws IOException {
// Check the content length to prevent denial of service attacks
int length = req.getContentLength();
if (length > maxSize) {
throw new IOException("Posted content length of " + length +
" exceeds limit of " + maxSize);
// Check the content type to make sure it's "multipart/form-data"
// Access header two ways to work around WebSphere oddities
String type = null;
String type1 = req.getHeader("Content-Type");
String type2 = req.getContentType();
// If one value is null, choose the other value
if (type1 == null && type2 != null) {
type = type2;
else if (type2 == null && type1 != null) {
type = type1;
// If neither value is null, choose the longer value
else if (type1 != null && type2 != null) {
type = (type1.length() > type2.length() ? type1 : type2);
if (type == null ||
!type.toLowerCase().startsWith("multipart/form-data")) {
throw new IOException("Posted content type isn't multipart/form-data");
// Get the boundary string; it's included in the content type.
// Should look something like "------------------------12012133613061"
String boundary = extractBoundary(type);
if (boundary == null) {
throw new IOException("Separation boundary was not specified");
// Construct the special input stream we'll read from
MultipartInputStreamHandler in =
new MultipartInputStreamHandler(req.getInputStream(), length);
// Read the first line, should be the first boundary
String line = in.readLine();
if (line == null) {
throw new IOException("Corrupt form data: premature ending");
// Verify that the line is the boundary
if (!line.startsWith(boundary)) {
throw new IOException("Corrupt form data: no leading boundary");
// Now that we're just beyond the first boundary, loop over each part
boolean done = false;
while (!done) {
done = readNextPart(in, boundary);
// A utility method that reads an individual part. Dispatches to
// readParameter() and readAndSaveFile() to do the actual work. A
// subclass can override this method for a better optimized or
// differently behaved implementation.
protected boolean readNextPart(MultipartInputStreamHandler in,
String boundary) throws IOException {
// Read the first line, should look like this:
// content-disposition: form-data; name="field1"; filename="file1.txt"
String line = in.readLine();
if (line == null) {
// No parts left, we're done
return true;
else if (line.length() == 0) {
// IE4 on Mac sends an empty line at the end; treat that as the end.
// Thanks to Daniel Lemire and Henri Tourigny for this fix.
return true;
// Parse the content-disposition line
String[] dispInfo = extractDispositionInfo(line);
String disposition = dispInfo[0];
String name = dispInfo[1];
String filename = dispInfo[2];
// Now onto the next line. This will either be empty
// or contain a Content-Type and then an empty line.
line = in.readLine();
if (line == null) {
// No parts left, we're done
return true;
// Get the content type, or null if none specified
String contentType = extractContentType(line);
if (contentType != null) {
// Eat the empty line
line = in.readLine();
if (line == null || line.length() > 0) { // line should be empty
throw new
IOException("Malformed line after content type: " + line);
else {
// Assume a default content type
contentType = "application/octet-stream";
// Now, finally, we read the content (end after reading the boundary)
if (filename == null) {
// This is a parameter, add it to the vector of values
String value = readParameter(in, boundary);
if (value.equals("")) {
value = null; // treat empty strings like nulls
Vector existingValues = (Vector)parameters.get(name);
if (existingValues == null) {
existingValues = new Vector();
parameters.put(name, existingValues);
existingValues.addElement(value);
else {
// This is a file
readAndSaveFile(in, boundary, filename, contentType);
if (filename.equals(NO_FILE)) {
files.put(name, new UploadedFile(null, null, null));
else {
files.put(name,
new UploadedFile(dir.toString(), filename, contentType));
return false; // there's more to read
// A utility method that reads a single part of the multipart request
// that represents a parameter. A subclass can override this method
// for a better optimized or differently behaved implementation.
protected String readParameter(MultipartInputStreamHandler in,
String boundary) throws IOException {
StringBuffer sbuf = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith(boundary)) break;
sbuf.append(line + "\r\n"); // add the \r\n in case there are many lines
if (sbuf.length() == 0) {
return null; // nothing read
sbuf.setLength(sbuf.length() - 2); // cut off the last line's \r\n
return sbuf.toString(); // no URL decoding needed
// A utility method that reads a single part of the multipart request
// that represents a file, and saves the file to the given directory.
// A subclass can override this method for a better optimized or
// differently behaved implementation.
protected void readAndSaveFile(MultipartInputStreamHandler in,
String boundary,
String filename,
String contentType) throws IOException {
OutputStream out = null;
// A filename of NO_FILE means no file was sent, so just read to the
// next boundary and ignore the empty contents
if (filename.equals(NO_FILE)) {
out = new ByteArrayOutputStream(); // write to nowhere
// A MacBinary file goes through a decoder
else if (contentType.equals("application/x-macbinary")){
File f = new File(dir + File.separator + filename);
out = new MacBinaryDecoderOutputStream(
new BufferedOutputStream(
new FileOutputStream(f), 8 * 1024));
// A real file's contents are written to disk
else {
File f = new File(dir + File.separator + filename);
out = new BufferedOutputStream(new FileOutputStream(f), 8 * 1024);
byte[] bbuf = new byte[100 * 1024]; // 100K
int result;
String line;
// ServletInputStream.readLine()
// adds a \r\n to the end of the last line.
// Since we want a byte-for-byte transfer, we have to cut those chars.
boolean rnflag = false;
while ((result = in.readLine(bbuf, 0, bbuf.length)) != -1) {
// Check for boundary
if (result > 2 && bbuf[0] == '-' && bbuf[1] == '-') { // quick pre-check
line = new String(bbuf, 0, result, "ISO-8859-1");
if (line.startsWith(boundary)) break;
// Are we supposed to write \r\n for the last iteration?
if (rnflag) {
out.write('\r'); out.write('\n');
rnflag = false;
// Write the buffer, postpone any ending \r\n
if (result >= 2 &&
bbuf[result - 2] == '\r' &&
bbuf[result - 1] == '\n') {
out.write(bbuf, 0, result - 2); // skip the last 2 chars
rnflag = true; // make a note to write them on the next iteration
else {
out.write(bbuf, 0, result);
out.flush();
out.close();
// Extracts and returns the boundary token from a line.
private String extractBoundary(String line) {
// Use lastIndexOf() because IE 4.01 on Win98 has been known to send the
// "boundary=" string multiple times. Thanks to David Wall for this fix.
int index = line.lastIndexOf("boundary=");
if (index == -1) {
return null;
String boundary = line.substring(index + 9); // 9 for "boundary="
// The real boundary is always preceeded by an extra "--"
boundary = "--" + boundary;
return boundary;
// Extracts and returns disposition info from a line, as a String array
// with elements: disposition, name, filename. Throws an IOException
// if the line is malformatted.
private String[] extractDispositionInfo(String line) throws IOException {
// Return the line's data as an array: disposition, name, filename
String[] retval = new String[3];
// Convert the line to a lowercase string without the ending \r\n
// Keep the original line for error messages and for variable names.
String origline = line;
line = origline.toLowerCase();
// Get the content disposition, should be "form-data"
int start = line.indexOf("content-disposition: ");
int end = line.indexOf(";");
if (start == -1 || end == -1) {
throw new IOException("Content disposition corrupt: " + origline);
String disposition = line.substring(start + 21, end);
if (!disposition.equals("form-data")) {
throw new IOException("Invalid content disposition: " + disposition);
// Get the field name
start = line.indexOf("name=\"", end); // start at last semicolon
end = line.indexOf("\"", start + 7); // skip name=\"
if (start == -1 || end == -1) {
throw new IOException("Content disposition corrupt: " + origline);
String name = origline.substring(start + 6, end);
// Get the filename, if given
String filename = null;
start = line.indexOf("filename=\"", end + 2); // start after name
end = line.indexOf("\"", start + 10); // skip filename=\"
if (start != -1 && end != -1) { // note the !=
filename = origline.substring(start + 10, end);
// The filename may contain a full path. Cut to just the filename.
int slash =
Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
if (slash > -1) {
filename = filename.substring(slash + 1); // past last slash
if (filename.equals("")) filename = NO_FILE; // sanity check
// Return a String array: disposition, name, filename
retval[0] = disposition;
retval[1] = name;
retval[2] = filename;
return retval;
// Extracts and returns the content type from a line, or null if the
// line was empty. Throws an IOException if the line is malformatted.
private String extractContentType(String line) throws IOException {
String contentType = null;
// Convert the line to a lowercase string
String origline = line;
line = origline.toLowerCase();
// Get the content type, if any
if (line.startsWith("content-type")) {
int start = line.indexOf(" ");
if (start == -1) {
throw new IOException("Content type corrupt: " + origline);
contentType = line.substring(start + 1);
else if (line.length() != 0) { // no content type, so should be empty
throw new IOException("Malformed line after disposition: " + origline);
return contentType;
// A class to hold information about an uploaded file.
class UploadedFile {
private String dir;
private String filename;
private String type;
UploadedFile(String dir, String filename, String type) {
this.dir = dir;
this.filename = filename;
this.type = type;
public String getContentType() {
return type;
public String getFilesystemName() {
return filename;
public File getFile() {
if (dir == null || filename == null) {
return null;
else {
return new File(dir + File.separator + filename);
// A class to aid in reading multipart/form-data from a ServletInputStream.
// It keeps track of how many bytes have been read and detects when the
// Content-Length limit has been reached.
class MultipartInputStreamHandler {
ServletInputStream in;
int totalExpected;
int totalRead = 0;
byte[] buf = new byte[8 * 1024];
public MultipartInputStreamHandler(ServletInputStream in,
int totalExpected) {
this.in = in;
this.totalExpected = totalExpected;
// Reads the next line of input. Returns null to indicate the end
// of stream.
public String readLine() throws IOException {
StringBuffer sbuf = new StringBuffer();
int result;
String line;
do {
result = this.readLine(buf, 0, buf.length); // this.readLine() does +=
if (result != -1) {
sbuf.append(new String(buf, 0, result, "ISO-8859-1"));
} while (result == buf.length); // loop only if the buffer was filled
if (sbuf.length() == 0) {
return null; // nothing read, must be at the end of stream
sbuf.setLength(sbuf.length() - 2); // cut off the trailing \r\n
return sbuf.toString();
// A pass-through to ServletInputStream.readLine() that keeps track
// of how many bytes have been read and stops reading when the
// Content-Length limit has been reached.
public int readLine(byte b[], int off, int len) throws IOException {
if (totalRead >= totalExpected) {
return -1;
else {
if (len > (totalExpected - totalRead)) {
len = totalExpected - totalRead; // keep from reading off end
int result = in.readLine(b, off, len);
if (result > 0) {
totalRead += result;
return result;
// Class to filters MacBinary files to normal files on the fly
// Optimized for speed more than readability
class MacBinaryDecoderOutputStream extends FilterOutputStream {
int bytesFiltered = 0;
int dataForkLength = 0;
public MacBinaryDecoderOutputStream(OutputStream out) {
super(out);
public void write(int b) throws IOException {
// Bytes 83 through 86 are a long representing the data fork length
// Check <= 86 first to short circuit early in the common case
if (bytesFiltered <= 86 && bytesFiltered >= 83) {
int leftShift = (86 - bytesFiltered) * 8;
dataForkLength = dataForkLength | (b & 0xff) << leftShift;
// Bytes 128 up to (128 + dataForkLength - 1) are the data fork
else if (bytesFiltered < (128 + dataForkLength) && bytesFiltered >= 128) {
out.write(b);
bytesFiltered++;
public void write(byte b[]) throws IOException {
write(b, 0, b.length);
public void write(byte b[], int off, int len) throws IOException {
// If the write is for content past the end of the data fork, ignore
if (bytesFiltered >= (128 + dataForkLength)) {
bytesFiltered += len;
// If the write is entirely within the data fork, write it directly
else if (bytesFiltered >= 128 &&
(bytesFiltered + len) <= (128 + dataForkLength)) {
out.write(b, off, len);
bytesFiltered += len;
// Otherwise, do the write a byte at a time to get the logic above
else {
for (int i = 0 ; i < len ; i++) {
write(b[off + i]);I am also need to rename a file and extension while uploadinf the file to the server. The oreilly example seems only save as the same file name and ext. I wonder if you have the ability chANGE OIT OR NOT. pLEASE LET ME KNOW
thanks
kansen -
Automatically renaming an uploaded file
I am creating a page to upload files, as well as to submit
data about the file to be stored in a database. When the form data
is submitted, how can I program it to automatically rename the
uploaded file to the ID or Key number of the row in the database in
which the file's information is stored?What scripting language are you using?
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"AngryCloud" <[email protected]> wrote in
message
news:evmlp4$lfh$[email protected]..
>I am creating a page to upload files, as well as to
submit data about the
>file
> to be stored in a database. When the form data is
submitted, how can I
> program
> it to automatically rename the uploaded file to the ID
or Key number of
> the row
> in the database in which the file's information is
stored?
> -
Return renamed uploaded file name
Hey,
I'm trying to upload a file from flash(selected via
filereference) via php, i rename(in php) the file before uploading
it. this isn't a problem and works great but then i need to return
the new filename to flash so i can save a link to it in my
database.
my biggest problem is that i use file.upload(phpScriptPath)
to upload the file. But if i use the echo command in php to return
newFilename i don't know how to capture this information in flash.
does anybody help me out?
thx on advanceYou can't return the new filename using the FileReference
object so you need a workaround. From what you posted here I can't
put my finger on the right solution but to illustrate:
I needed a solution as part of a form where the user would
provide name, email and so on and could upload a c.v. Before the
file upload I used a LoadVars (and used the sendAndLoad() method)
object to post the data from the form and return the record_id from
the database. In the onLoad event of the LoadVars object I used the
FileReference object to handle the upload, calling an upload script
and added the record_id as a get variable. The record_id was then
used to save the new filename of the uploaded file to the database.
If this is not feasible in your situation, elaborate on the
topic by describing your scenario in more detail. -
Creaky MuVo battery pack? Also, warmness after uploading files (renamed thre
Sorry to keep making threads about little things, but I reckon it's worth checking. My MuVo feels quite a bit hotter after I upload files to it (completely fill over USB2.0 usually). It cools down in a few minutes, but I thought I'd check to see if it's normal behaviour. If it's relevant, the USB connector on the main bit (with the controls) is squint (angled towards the screen face of the player).
Also, my battery module's a bit creaky. When I press buttons on the player or swap the battery I can feel it creaking into different positions. The main player doesn't do this on its own, so I'm wondering if all the battery modules are like that. If not, I might send off for a new battery module as it's only about ?9 and it'd really improve the feel of the player (I hate cheap-feeling plastic if it's something I'm handling a lot).
Edit- Just to elaborate on the "creaky" thing, the battery pack feels really loose and plasticky on its own and when the main player bit's plugged in. This makes the whole thing feel a bit fiddly, creaking when I press down on buttons or the scroller, when in fact the player bit itself feels solid on its own.
Now, if I pop the player in the belt clip holster widget, it suddenly "tightens" up, presumably because the holster is pressing in around the player. It feels really, really solid. Is the problem shared by all the battery packs, or have I just mistreated mine a bit's If it's the latter I'll nab a new battery pack.Message Edited by Sockatume on 06-20-2005 03:44 AMMy Zen Micro heated up a bit when I was charging/transferring files too. I just unplugged it and in a few minutes it was fine. So that seems to be normal. Don't know about the other problem though, sorry.
-
Adobe Muse won't publish (Error uploading file)
After making simple animations using Adobe Edge Animate it seems as though none of the assets will publish with my site after importing them into Muse.
In Edge animate I saved for "web animation" and published. Then I went to muse and hit "place". I went to preview and everything works fine. When I go to publish there are always errors in uploading my assets with '.png' extensions.
Any help is much appreciated. I have completely scrapped my website and created another, reinstalled Animate and have renamed all my files, I'm not sure whats wrong here.
I got one animation working, and that can be seen here under the Photography section, but I have multiples that will be shown on my page at one time.
http://chasebodydesign.businesscatalyst.comI get the error uploading file everytime I try publishing the animation.
Maybe you are looking for
-
I lost my apple tv remote but I want to set up my sell phone to pair with apple tv
-
Facetime on MacBook Pro, Iphone and Ipad mini no longer works?
Facetime on MacBook Pro, Iphone and Ipad mini no longer works after years of working just fine. I get the message that I am connecting then it instantly just disconnects. Has worked fine for over two years with no issue until about a month ago? I hav
-
Multiple libraries with independent settings?
I don't see that this can be done, but is it possible to have two libraries where on manages the content and the other does not? I want mymusic to be automatically added to the library via the iTunes process of doing so (not interested in doing it m
-
Expense Report Export - Payment Method is invalid
Hi all, We are using 12.1.3 . We entered data for creating invoices via Payables > Invoice > Entry > Expense Reports. After submitted Expense Report Export with source - Payables Expense Reports no invoices was created. We can see in Expenses: Export
-
Star ratings on iphone aren't displaying proplerly in itunes
Hello, I am new to the community, so this may be a very stupid problem that i am having. No matter how many times i sync my iphone with itunes, the star ratings that i have assigned songs on my iphone will not display correctly in itunes. I understan