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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题