美图api头像编辑器xiuxiu.setUploadURL设置问题

w252224724 2015-07-22 04:24:45
http://open.web.meitu.com/products/#M4


<script type="text/javascript">
window.onload = function () {
/*第1个参数是加载编辑器div容器,第2个参数是编辑器类型,第3个参数是div容器宽,第4个参数是div容器高*/
xiuxiu.embedSWF("altContent", 5, "50%", "100%");
//修改为您自己的图片上传接口
xiuxiu.setUploadURL("http://localhost:37674/GZSoftWeb/Common/stream.ashx");【这个url对吗?】
xiuxiu.setUploadType(2);
xiuxiu.setUploadDataFieldName("upload_file");
xiuxiu.onInit = function () {
xiuxiu.loadPhoto("http://localhost:37674/GZSoftWeb/Programs/img/undefined1.png");
}
xiuxiu.onUploadResponse = function (data) {
alert("上传响应" + data); // 可以开启调试
}
}
</script>

上面的url路径对吗,浏览器能够打开http://localhost:37674/GZSoftWeb/Common/stream.ashx,但是头像编辑器无法工作

-------------------------------------下面是美图上下载的内容--------------------------------------------------
stream.ashx内容
<%@ WebHandler Language="C#" CodeBehind="stream.ashx.cs" Class="XiuXiuWeb.stream" %>

stream.ashx.cs内容
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.IO;
using System.Drawing;
using XiuXiuWeb.XiuXiuStream;

namespace XiuXiuWeb
{
/// <summary>
/// Summary description for stream
/// </summary>
public class stream : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
//config 配置节点可以将图片保存至指定目录,未配置将保存至 /XiuXiuUpload
//<appSettings>
// <add key="XiuXiuImageSavePath" value="/upload"/>
//</appSettings>
string name = null;
if (context.Request.TotalBytes > 0)
{
XiuXiuStreamImage img = new XiuXiuStreamImage(context);
name = img.Save();
}
else
{
name = "非法访问";
}
context.Response.ContentType = "text/plain";
context.Response.Write(name);
}

public bool IsReusable
{
get
{
return false;
}
}
}

namespace XiuXiuStream
{

/// <summary>
/// 上传抽象类
/// </summary>
public abstract class XiuXiuImage
{
/// <summary>
/// 基类保存
/// </summary>
/// <returns>返回保存路径+文件名</returns>
public virtual string Save()
{
string fileName = this.GetFileName();
if (null == fileName) return null;

string root = HttpContext.Current.Server.MapPath(path);

if (!Directory.Exists(root))
{
Directory.CreateDirectory(root);
}

this.FileName = Path.Combine(root, fileName);
string[] paths = { path, fileName };
return string.Join("/", paths);
}

public XiuXiuImage()
{
path = path == null ? "/XiuXiuUpload" : path;
}

/// <summary>
/// 确定上传类型
/// </summary>
protected bool IsUplodType
{
get
{
string extension = this.GetExtension();
return ".jpg .gif .png .icon .bmp .tiff .wmf .emf .exif".IndexOf(extension) >= 0 ? true : false;
}
}
private string _fileName = null;
/// <summary>
/// 最终保存路径
/// </summary>
protected string FileName
{
set { _fileName = value; }
get { return _fileName; }
}

/// <summary>
/// 配置文件路径 无配置上传到XiuXiuUpload
/// </summary>
protected string path = ConfigurationManager.AppSettings["XiuXiuImageSavePath"];

/// <summary>
/// 获取拓展名
/// </summary>
/// <returns></returns>
protected abstract string GetExtension();

/// <summary>
/// 获取最终保存文件名
/// </summary>
/// <returns></returns>
protected string GetFileName()
{
string extension = this.GetExtension();
if (null == extension) return null;
else
{
string name = this.GetName();
string[] imgName = { "XiuXiu", name, extension };
return string.Join("", imgName);
}
}
/// <summary>
/// 获取保存文件名
/// </summary>
/// <returns></returns>
private string GetName()
{
DateTime uploadTime = DateTime.Now;
string[] times = { uploadTime.Year.ToString(), uploadTime.Month.ToString(), uploadTime.Day.ToString(),
uploadTime.Hour.ToString(), uploadTime.Millisecond.ToString(), uploadTime.Second.ToString() };
return string.Join("", times);
}
}
/// <summary>
/// Stream接收
/// </summary>
public sealed class XiuXiuStreamImage : XiuXiuImage
{
private MemoryStream stream = null;

public XiuXiuStreamImage(HttpContext context)
{
int count = context.Request.TotalBytes;
if (count > 0)
{
byte[] bytes = context.Request.BinaryRead(context.Request.TotalBytes);
this.stream = new MemoryStream(bytes);
}
}

private Image File
{
get
{
return this.stream == null ? null : Image.FromStream(this.stream);
}
}
/// <summary>
/// 保存图片,成功返回文件路径,失败null
/// 非图片格式返回错误信息
/// </summary>
/// <returns>成功返回文件路径 失败null</returns>
public override string Save()
{
if (!this.IsUplodType)
{
this.stream.Dispose();
return "Only allowed to upload pictures.";
}
string returnName = base.Save();
if (this.FileName != null)
{
this.File.Save(this.FileName);
this.stream.Dispose();
return returnName;
}
return null;
}

protected override string GetExtension()
{
if (this.File != null)
{
string fileExtension = this.File.RawFormat.ToString().Substring(14),
jpgExtension = System.Drawing.Imaging.ImageFormat.Jpeg.Guid.ToString(),
gifExtension = System.Drawing.Imaging.ImageFormat.Gif.Guid.ToString(),
pngExtension = System.Drawing.Imaging.ImageFormat.Png.Guid.ToString(),
iconExtension = System.Drawing.Imaging.ImageFormat.Icon.Guid.ToString(),
bmpExtension = System.Drawing.Imaging.ImageFormat.Bmp.Guid.ToString(),
tiffExtension = System.Drawing.Imaging.ImageFormat.Tiff.Guid.ToString(),
wmfExtension = System.Drawing.Imaging.ImageFormat.Wmf.Guid.ToString(),
emfExtension = System.Drawing.Imaging.ImageFormat.Emf.Guid.ToString(),
exifExtension = System.Drawing.Imaging.ImageFormat.Exif.Guid.ToString();
fileExtension = fileExtension.Substring(0, fileExtension.Length - 1);
if (fileExtension == jpgExtension)
{
return ".jpg";
}
else if (fileExtension == gifExtension)
{
return ".gif";
}
else if (fileExtension == pngExtension)
{
return ".png";
}
else if (fileExtension == iconExtension)
{
return ".icon";
}
else if (fileExtension == bmpExtension)
{
return ".bmp";
}
else if (fileExtension == tiffExtension)
{
return ".tiff";
}
else if (fileExtension == wmfExtension)
{
return ".wmf";
}
else if (fileExtension == emfExtension)
{
return ".emf";
}
else if (fileExtension == exifExtension)
{
return ".exif";
}
}
return null;
}
}
}
}
...全文
289 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
放肆看 2015-07-24
  • 打赏
  • 举报
回复
引用 6 楼 w252224724 的回复:
可能是找到原因了,“GET http://localhost:37674/crossdomain.xml 404 (Not Found) ” 我的crossdomain.xml 的路径是http://localhost:37674/GZSoftWeb/crossdomain.xml,但是现在好像没办法把这个文件放根目录下
网站属性——虚拟路径——改为空
w252224724 2015-07-24
  • 打赏
  • 举报
回复
可能是找到原因了,“GET http://localhost:37674/crossdomain.xml 404 (Not Found) ”

我的crossdomain.xml 的路径是http://localhost:37674/GZSoftWeb/crossdomain.xml,但是现在好像没办法把这个文件放根目录下
w252224724 2015-07-24
  • 打赏
  • 举报
回复
upppppppppppppppppppppppp
Hello World, 2015-07-23
  • 打赏
  • 举报
回复
官网的示例代码要改下,你用的流式上传将xiuxiu.setUploadType(2);改为xiuxiu.setUploadType(1);
w252224724 2015-07-23
  • 打赏
  • 举报
回复
引用 3 楼 apollokk 的回复:
官网的示例代码要改下,你用的流式上传将xiuxiu.setUploadType(2);改为xiuxiu.setUploadType(1);
web应用程序能够上传,但是我的是web空网站,网站就无法上传了
Justin-Liu 2015-07-23
  • 打赏
  • 举报
回复
用相对路径试试
w252224724 2015-07-22
  • 打赏
  • 举报
回复
uppppppppp

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧