sinat_25213573 2015-04-17 04:54 采纳率: 16.7%
浏览 1663

求解文件上传的路径问题

///
/// 上传文件
///
/// 上传Token
/// key
/// 本地文件名
public CallRet PutFile(string upToken, string localFile, string key)
{
if (!File.Exists(localFile))
{
throw new Exception(string.Format("{0} does not exist", localFile));
}

        PutAuthClient client = new PutAuthClient(upToken);
        CallRet ret;
        using (FileStream fs = File.OpenRead(localFile))
        {
            int block_cnt = block_count(fs.Length);
            long fsize = fs.Length;
            extra.Progresses = new BlkputRet[block_cnt];
            byte[] byteBuf = new byte[BLOCKSIZE];
            int readLen = BLOCKSIZE;
            for (int i = 0; i < block_cnt; i++)
            {
                if (i == block_cnt - 1) { 
                    readLen = (int)(fsize - (long)i * BLOCKSIZE);
                }
                fs.Seek((long)i * BLOCKSIZE, SeekOrigin.Begin);
                fs.Read(byteBuf, 0, readLen);
                BlkputRet blkRet = ResumableBlockPut(client, byteBuf, i, readLen);
                if (blkRet == null)
                {
                    extra.OnNotifyErr(new PutNotifyErrorEvent(i, readLen, "Make Block Error"));
                }
                else
                {
                    extra.OnNotify(new PutNotifyEvent(i, readLen, extra.Progresses[i]));
                }
            }
            ret = Mkfile(client, key, fsize);
        }
        if (ret.OK)
        {
            if (PutFinished != null)
            {
                PutFinished(this, ret);
            }
        }
        else
        {
            if (PutFailure != null)
            {
                PutFailure(this, ret);
            }
        }
        return ret;
    }

参数localfile应该是文件的绝对路径,如果用input:file 上传,后台怎么获取上传文件的绝对路径赋给这个参数啊?

  • 写回答

1条回答 默认 最新

  • devmiao 2015-04-18 05:49
    关注

    一些浏览器不会发送上传路径,而且客户端的路径对你来说也没有意义。

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏