| | |
| | | } |
| | | |
| | | // 生成唯一文件名 |
| | | String uniqueFileName = fileName+ "_" + UUID.randomUUID().toString() ; |
| | | String uniqueFileName = UUID.randomUUID().toString()+ "_" + fileName ; |
| | | Path targetFilePath = uploadPath.resolve(uniqueFileName); |
| | | |
| | | // 构建公司专属分片目录 |
| | |
| | | } else { |
| | | log.debug("收到完整文件请求,返回初始片段"); |
| | | |
| | | // 没有Range头,返回初始片段(约30秒内容) |
| | | long actualEnd = Math.min(MAX_INITIAL_SEGMENT, fileSize - 1); |
| | | // 没有Range头,返回文件大小的10分之一和15MB中较小的那个 |
| | | long oneTenthSize = fileSize / 10; |
| | | // 计算10分之一和15MB的较小值 |
| | | long maxInitialSize = Math.min(oneTenthSize, MAX_INITIAL_SEGMENT); |
| | | // 确保至少返回1字节,且不超过文件大小 |
| | | long actualEnd = Math.min(Math.max(maxInitialSize, 1), fileSize - 1); |
| | | log.debug("返回初始片段: {} bytes (10分之一大小: {} bytes, 15MB限制: {} bytes, 文件总大小: {} bytes)", |
| | | actualEnd + 1, oneTenthSize, MAX_INITIAL_SEGMENT, fileSize); |
| | | |
| | | // 设置响应状态和头部信息 |
| | | response.setStatus(HttpStatus.PARTIAL_CONTENT.value()); // 使用206状态码,因为只返回部分内容 |