1

我有这个 radupload:

 <telerik:RadUpload ID="RadAsyncUploadBoxLogo"  ClientID="RadAsyncUploadBoxLogo"

                                                            runat="server" ControlObjectsVisibility="None"
                                                            MaxFileInputsCount="1" MaxFileSize="4000000" OverwriteExistingFiles="True" ReadOnlyFileInputs="True"
                                                           Height="10px" TabIndex="12" OnClientFileSelected="OnClientFileSelectedHandler"
                                                            >
                                                            <Localization Remove="" Select=" Seleccionar Imagen" />
                                                        </telerik:RadUpload>

我有这个标签图片

 <asp:Image ID="ImageLogo" ClientId="ImageLogo" CssClass="ImgLogo" runat="server"/>

使用此脚本,我尝试将图像放在图像标签中:

function myOnClientFileSelect(radUpload, eventArgs) {

    var url = radUpload.getFileInputs()[0].Value;
    $('.ImgLogo').attr("src", url);

}

问题是变量 url 向我抛出了一个路径: fakepath/filename ,我读到 radupload 抛出了安全问题,因此其他人无法访问文件路径,而是如何获取文件的真实路径以将其显示在标记图像

4

1 回答 1

2

在哪里file_input是对 a 的引用<input type="file">并且img是对 a 的引用<img>,在更改处理程序中你可以做

if (file_input.files && file_input.files.length) { // some file has been set
    // generate a blob uri to the file
    var uri = URL.createObjectURL(file_input.files[0]);
    // set this as the src of your <img>
    img.src = uri;
}

此代码使用URL.createObjectURL需要IE 10+,为了支持较低版本的IE,您可能需要使用 a<canvas>而不是 an<img>以便您可以以不同方式加载文件。

于 2015-03-06T18:16:46.297 回答