Skip to content

Commit

Permalink
optimize get network file info
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Oct 10, 2023
1 parent a238df1 commit 33baccb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions iqshell/common/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/qiniu/qshell/v2/iqshell/common/data"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/qiniu/qshell/v2/iqshell/common/client"
"github.com/qiniu/qshell/v2/iqshell/common/data"
)

const (
Expand Down Expand Up @@ -128,11 +130,16 @@ func NetworkFileLength(srcResUrl string) (fileSize int64, err *data.CodeError) {

func GetNetworkFileInfo(srcResUrl string) (*NetworkFileInfo, *data.CodeError) {

resp, respErr := http.Head(srcResUrl)
resp, respErr := client.DefaultStorageClient().Head(srcResUrl)
if respErr != nil {
return nil, data.NewEmptyError().AppendDescF("New head request failed, %s", respErr.Error())
}
defer resp.Body.Close()
defer func() {
if resp.Body != nil {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}
}()

file := &NetworkFileInfo{
Size: -1,
Expand Down

0 comments on commit 33baccb

Please sign in to comment.